版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

78 lines
2.1 KiB

  1. const $ = require('../index');
  2. const config = require('./config');
  3. const jc1 = require('./code/simple1');
  4. const jv = require('./code/simple-vue');
  5. const hc1 = require('./code/simple1.html');
  6. test('$.clone: empty code', () => {
  7. expect(()=>{
  8. const G = $('');
  9. G.clone();
  10. }).not.toThrow();
  11. })
  12. test('$.clone: simple code', () => {
  13. expect(()=>{
  14. const G = $('var a = 1;');
  15. G.clone();
  16. }).not.toThrow();
  17. })
  18. test('$.clone: this[0] is null', () => {
  19. expect(()=>{
  20. const G = $('var a = 1;');
  21. G[0] = null
  22. G.clone();
  23. }).not.toThrow();
  24. })
  25. test('$.clone: this[0] is null,return should be self', () => {
  26. const G = $('var a = 1;');
  27. G[0] = null
  28. const newOne = G.clone();
  29. expect(!!newOne).toBeTruthy();
  30. })
  31. test('$.clone: should not be the same instance', () => {
  32. const G = $('var a = 1;');
  33. const newG = G.clone();
  34. expect(G === newG).not.toBeTruthy();
  35. })
  36. test('$.clone: deep equal ',()=>{
  37. const G = $('var a = 1;');
  38. const newG = G.clone();
  39. // expect(G.node).toEqual(newG.node);
  40. })
  41. test('$.clone: simple1 html code', () => {
  42. expect(() => {
  43. const G = $(hc1, config.html);
  44. const newG = G.clone();
  45. }).not.toThrow();
  46. })
  47. test('$.clone: simple1 html code result should be ok', () => {
  48. const G = $(hc1, config.html);
  49. const newG = G.clone();
  50. expect(newG.node).toEqual(G.node);
  51. })
  52. test('$.clone: simple1 html code result should be ok', () => {
  53. const G = $(hc1, config.html).find('<span>$_$</span>');
  54. const newG = G.clone();
  55. expect(newG.node).toEqual(G.node);
  56. })
  57. test('$.clone: test vue', () => {
  58. expect(() => {
  59. $(jv, config.vue)
  60. .find('<template></template>').find('<$_$1 v-for=$_$2>').each(function (ast) {
  61. const newAst = ast.clone();
  62. console.log(newAst);
  63. });
  64. }).not.toThrow();
  65. })
  66. test('$.clone: test vue', () => {
  67. const newAst = $(`const a = {
  68. age: 22,
  69. some: 'foo'
  70. }`)
  71. .clone()
  72. expect(newAst.find('const a = { $$$ }').generate().match('age')).toBeTruthy()
  73. })