版博士V2.0程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

G.remove.test.js 4.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. const $ = require('../index');
  2. const config = require('./config');
  3. const jc1 = require('./code/simple1');
  4. const jc2 = require('./code/simple2');
  5. const jTryout = require('./code/simple-tryout');
  6. const hc1 = require('./code/simple1.html');
  7. test('$.remove: no selector', () => {
  8. expect(()=>{
  9. const G = $('var a = 1;');
  10. G.remove();
  11. }).toThrow();
  12. })
  13. test('$.remove: siple code', () => {
  14. expect(()=>{
  15. const G = $('var a = 1;');
  16. G.remove('var $_$ ');
  17. }).not.toThrow();
  18. })
  19. test('$.remove: this[0] is null', () => {
  20. expect(()=>{
  21. const G = $('var a = 1;');
  22. G[0] = null
  23. G.remove();
  24. }).not.toThrow();
  25. })
  26. test('$.remove: simple code 2', () => {
  27. expect(() => {
  28. const code = `
  29. function parent(){
  30. let name = 'jerry';
  31. let city = 'bj';
  32. function eat(){
  33. console.log('do eat');
  34. }
  35. }
  36. parent();
  37. `
  38. const G = $(code).remove('let $_$ = \'$_$\'');
  39. }).not.toThrow()
  40. })
  41. test('$.remove: simple code 2', () => {
  42. expect(() => {
  43. const code = `
  44. function parent(){
  45. let name = 'jerry';
  46. let city = 'bj';
  47. function eat(){
  48. console.log('do eat');
  49. }
  50. }
  51. parent();
  52. `
  53. const G = $(code).remove('let $_$ = \'$_$\'');
  54. }).not.toThrow()
  55. })
  56. test('$.remove: simple code 2 result should be ok', () => {
  57. const code = `
  58. function parent(){
  59. let name = 'jerry';
  60. let city = 'bj';
  61. function eat(){
  62. console.log('do eat');
  63. }
  64. }
  65. parent();
  66. `
  67. const G = $(code).remove('let $_$ = \'$_$\'');
  68. const result = G.generate();
  69. expect(result.indexOf(`let name = 'jerry'` < 0)).toBeTruthy();
  70. })
  71. test('$.remove: remove code use find result should be ok', () => {
  72. const code = `
  73. function parent(){
  74. let name = 'jerry';
  75. let city = 'bj';
  76. function eat(){
  77. console.log('do eat');
  78. }
  79. }
  80. parent();
  81. `
  82. const G = $(code).find('parent()').remove();
  83. const result = G.root().generate();
  84. expect(result.indexOf(`parent()` < 0)).toBeTruthy();
  85. })
  86. // test('$.remove: simple2 code result should be ok', () => {
  87. // const G = $(jc2);
  88. // // G.remove('await this.fetchData();');
  89. // const result = G.generate();
  90. // expect(result.indexOf(`await this.fetchData()` < 0)).toBeTruthy();
  91. // })
  92. test('$.remove: simple tryout js code if condition should be remove', () => {
  93. // 删除掉非 391试用功能代码
  94. const code = $(jTryout).find(`if(!Tryout.TRYOUT_SID_391){$_$}`).remove()
  95. .root()
  96. .generate();
  97. const result = code.indexOf(`if (!Tryout.TRYOUT_SID_391)`) < 0
  98. expect(result).toBeTruthy();
  99. })
  100. test('$.remove: simple1 html code', () => {
  101. expect(() => {
  102. const G = $(hc1, config.html);
  103. G.remove('<span>test</span>')
  104. }).not.toThrow();
  105. })
  106. test('$.remove: simple1 html code result should be ok', () => {
  107. const G = $(hc1, config.html);
  108. G.remove('<span>test</span>');
  109. const code = G.generate();
  110. expect(code.indexOf('<span>test</span>') < 0).toBeTruthy();
  111. })
  112. test('$.remove: find result to remove ,result should be ok', () => {
  113. const G = $(hc1, config.html).find('<div id="1">$_$</div>');
  114. G.remove('<span>test</span>');
  115. const code = G.generate();
  116. expect(code.indexOf('<span>test</span>') < 0).toBeTruthy();
  117. })
  118. test('$.remove: find result to remove use $_$,result should be ok', () => {
  119. const G = $(hc1, config.html).find('<div id="1">$_$</div>');
  120. G.remove('<span>$_$</span>');
  121. const code = G.generate();
  122. expect(code.indexOf('<span>') < 0).toBeTruthy();
  123. })
  124. // todo 属性还不能这么匹配
  125. // test('$.remove: remove attr ,result should be ok', () => {
  126. // const G = $(hc1, config.html);
  127. // G.remove('id="1"');
  128. // //待定
  129. // const code = G.generate();
  130. // expect(code.indexOf('id="1"') < 0).toBeTruthy();
  131. // })
  132. test('$.remove: remove attr ,result should be ok', () => {
  133. const G = $(hc1, config.html);
  134. G.remove('<div id="1">');
  135. //待定
  136. const code = G.generate();
  137. expect(code.indexOf('id="1"') < 0).toBeTruthy();
  138. })