版博士V2.0程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

107 řádky
2.7 KiB

  1. const $ = require('../index');
  2. const config = require('./config');
  3. const jc1 = require('./code/simple1');
  4. const jc2 = require('./code/simple2');
  5. const hc1 = require('./code/simple1.html');
  6. test('$.prevAll: simple code', () => {
  7. expect(()=>{
  8. const G = $('var a = 1;');
  9. G.prevAll();
  10. }).not.toThrow();
  11. })
  12. test('$.prevAll: this[0] is null', () => {
  13. expect(()=>{
  14. const G = $('var a = 1;');
  15. G[0] = null
  16. G.prevAll();
  17. }).not.toThrow();
  18. })
  19. test('$.prevAll: simple code 2', () => {
  20. expect(() => {
  21. const code = `
  22. function test(){
  23. let a = 1;
  24. let b = 2;
  25. }
  26. test();
  27. `
  28. const G = $(code)
  29. const ss = G.prevAll()
  30. }).not.toThrow()
  31. })
  32. test('$.prevAll: simple code 3', () => {
  33. expect(() => {
  34. const code = `
  35. let obj = { a: 1, b: 2 };
  36. let c = obj.a + obj.b;
  37. `
  38. const G = $(code)
  39. const ss = G.prevAll()
  40. }).not.toThrow()
  41. })
  42. test('$.prevAll: simple code 4', () => {
  43. expect(() => {
  44. const code = `
  45. function parent(){
  46. function eat(){
  47. console.log('do eat');
  48. }
  49. let name = 'jerry';
  50. }
  51. parent();
  52. `
  53. const G = $(code).find('let $_$ = \'$_$\'');
  54. const ss = G.prevAll()
  55. }).not.toThrow()
  56. })
  57. test('$.prevAll: simple code 4', () => {
  58. const code = `
  59. function parent(){
  60. function eat(){
  61. console.log('do eat');
  62. }
  63. let name = 'jerry';
  64. }
  65. parent();
  66. `
  67. const G = $(code).find('let $_$ = \'$_$\'');
  68. const result = G.prevAll().generate()
  69. const compareCode = $(`function eat(){
  70. console.log('do eat');
  71. }`).generate();
  72. expect(result).toBe(compareCode);
  73. })
  74. test('$.prevAll: simple2 code result should be ok', () => {
  75. const G = $(jc2).find(`this.updater.digest({ list, total })`);
  76. const result = G.prevAll().generate()
  77. const compareCode = $(`const params = { name: '1' };`).generate();
  78. expect(result).toBe(compareCode);
  79. })
  80. test('$.prevAll: simple html code', () => {
  81. const code = `<div>test</div>`;
  82. expect(() => {
  83. const G = $(code, config.html);
  84. G.prevAll();
  85. }).not.toThrow();
  86. })
  87. test('$.prevAll: simple html code', () => {
  88. const code = `<div>
  89. <a href="xxx">is a link</a>
  90. <span>test</span>
  91. </div>`;
  92. expect(() => {
  93. const G = $(code, config.html).find('<span>$_$</span>');
  94. G.prevAll();
  95. }).not.toThrow();
  96. })
  97. test('$.prevAll: simple html code result should be ok', () => {
  98. const code = `<div>
  99. <a href="xxx">is a link</a>
  100. <span>test</span>
  101. </div>`;
  102. const G = $(code, config.html).find('<span>$_$</span>');
  103. const result = G.prevAll().generate();
  104. expect(result).toBe(`\n `);
  105. })