版博士V2.0程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

68 Zeilen
1.8 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. const CODE = `
  7. function parent(){
  8. let name = 'jerry';
  9. function eat(){
  10. console.log('do eat');
  11. }
  12. }
  13. `
  14. test('$.parents: simple code', () => {
  15. expect(()=>{
  16. const G = $('var a = 1;');
  17. G.parents();
  18. }).not.toThrow();
  19. })
  20. test('$.parents: this[0] is null', () => {
  21. expect(()=>{
  22. const G = $('var a = 1;');
  23. G[0] = null
  24. G.parents();
  25. }).not.toThrow();
  26. })
  27. test('$.parents: parents find', () => {
  28. expect(()=>{
  29. const G = $(CODE).find('let $_$ = $_$;');
  30. const parents = G.parents();
  31. const psCode = parents.generate();
  32. }).not.toThrow();
  33. })
  34. test('$.parents: parents find', () => {
  35. expect(()=>{
  36. const G = $(CODE).find('let $_$ = \'$_$\';');
  37. G.parents();
  38. }).not.toThrow();
  39. })
  40. test('$.parents: simple1 html code', () => {
  41. expect(() => {
  42. const G = $(hc1, config.html);
  43. G.parents();
  44. }).not.toThrow();
  45. })
  46. test('$.parents: simple2 code parents find result should be ok', () => {
  47. const G = $(jc2).find('this.render()');
  48. const parent = G.parents();
  49. const psCode = parent.eq(1).generate();
  50. expect(psCode).toBe(
  51. `{
  52. this.render()
  53. }`
  54. );
  55. })
  56. test('$.parents: simple1 html code result should be ok', () => {
  57. const G = $(hc1, config.html);
  58. const parent = G.parents();
  59. expect(!parent[0]).toBeTruthy();
  60. })
  61. test('$.parents: simple1 html code use find result should be ok', () => {
  62. const G = $(hc1, config.html);
  63. const parent = G.find('<title>title</title>').parents();
  64. const psCode = parent.generate();
  65. expect(psCode.indexOf('<head>' > -1)).toBeTruthy();
  66. })