版博士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.
 
 
 
 

63 rivejä
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. test('$.prepend: empty code should not throw error', () => {
  7. expect(()=>{
  8. const G = $('var a = 1;');
  9. G.prepend('');
  10. }).not.toThrow();
  11. })
  12. test('$.prepend: null should throw error', () => {
  13. expect(()=>{
  14. const G = $('var a = 1;');
  15. G.prepend(null);
  16. }).toThrow();
  17. })
  18. test('$.prepend: undefined should throw error', () => {
  19. expect(()=>{
  20. const G = $('var a = 1;');
  21. G.prepend(undefined);
  22. }).toThrow();
  23. })
  24. test('$.prepend: simple code', () => {
  25. expect(()=>{
  26. const CODE = `
  27. function a(){
  28. var a = 1;
  29. }
  30. `;
  31. $(CODE).prepend('var a = 1;');
  32. }).not.toThrow();
  33. })
  34. test('$.prepend: simple code result should to be passed', () => {
  35. const G = $(jc2).prepend($('{test:function(){}}').node);
  36. const result = G.node.program.body[0].properties[0].key.name === 'test';
  37. expect(result).toBeTruthy();
  38. });
  39. test('$.prepend: simple code', () => {
  40. expect(()=>{
  41. const G = $('var a = 1;');
  42. G.prepend($('var b = 1;'));
  43. }).not.toThrow();
  44. })
  45. test('$.prepend: simple code', () => {
  46. expect(()=>{
  47. const G = $('var a = 1;');
  48. G.prepend($('var b = 1;').node);
  49. }).not.toThrow();
  50. })
  51. test('$.prepend: simple html code', () => {
  52. const code = `<div>test</div>`;
  53. expect(() => {
  54. const G = $(code, config.html);
  55. G.prepend('<span>span</span>');
  56. }).not.toThrow();
  57. })
  58. test('$.prepend: simple1 html code result should to be ok', () => {
  59. const CODE = '<div>test prepend</div>'
  60. const G = $(hc1, config.html);
  61. const result = G.find('<html>').prepend(CODE).generate();
  62. expect(result.indexOf(CODE) > -1).toBeTruthy();
  63. })