版博士V2.0程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

121 wiersze
3.2 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('$.attr: empty code', () => {
  7. expect(()=>{
  8. const G = $('');
  9. G.attr('a','a');
  10. }).not.toThrow();
  11. })
  12. test('$.attr: get attr', () => {
  13. expect(() => {
  14. const G = $(jc1);
  15. const b = G.attr('program');
  16. }).not.toThrow();
  17. })
  18. test('$.attr: simple code get attr', () => {
  19. expect(()=>{
  20. const G = $(jc1);
  21. const body = G.attr('program.body');
  22. }).not.toThrow();
  23. })
  24. test('$.attr: simple code get attr should to be ok', () => {
  25. const G = $(jc1);
  26. const body = G.attr('program.body');
  27. expect(Array.isArray(body)).toBeTruthy();
  28. })
  29. // later
  30. // test('$.attr: simple code get attr should support array index ', () => {
  31. // const G = $(jc1);
  32. // const body0 = G.attr('program.body[0]');
  33. // expect(body0.kind === 'const').toBeTruthy();
  34. // })
  35. test('$.attr: simple code set attr', () => {
  36. expect(()=>{
  37. const G = $(jc1);
  38. G.attr('program.test','test');
  39. }).not.toThrow();
  40. })
  41. test('$.attr: simple code set attr result should be ok', () => {
  42. const G = $(jc1);
  43. G.attr('program.test','test');
  44. const result = G.node.program.test === 'test';
  45. expect(result).toBeTruthy();
  46. })
  47. test('$.attr: this[0] is null', () => {
  48. expect(()=>{
  49. const G = $('var a = 1;');
  50. G[0] = null
  51. G.attr();
  52. }).not.toThrow();
  53. })
  54. test('$.attr: object input', () => {
  55. expect(()=>{
  56. const G = $(jc1);
  57. G.attr({a:'a'});
  58. }).not.toThrow();
  59. })
  60. test('$.attr: object input result should be ok', () => {
  61. expect(()=>{
  62. const G = $(jc1);
  63. G.attr({a:'a'});
  64. }).not.toThrow();
  65. })
  66. test('$.attr: attr key should be a string', () => {
  67. expect(() => {
  68. const G = $(jc1);
  69. G.attr(1, 'a');
  70. }).toThrow();
  71. })
  72. test('$.attr: simple1 html code get attr', () => {
  73. expect(() => {
  74. const G = $(hc1, config.html);
  75. G.attr('content');
  76. }).not.toThrow();
  77. })
  78. test('$.attr: simple1 html code get attr', () => {
  79. expect(() => {
  80. const G = $(hc1, config.html);
  81. G.attr('content.children');
  82. }).not.toThrow();
  83. })
  84. test('$.attr: simple1 html code get attr', () => {
  85. const G = $(hc1, config.html);
  86. const result = G.attr('content.children');
  87. expect(Array.isArray(result)).toBeTruthy();
  88. })
  89. test('$.attr: simple1 html code set attr', () => {
  90. expect(() => {
  91. const G = $(hc1, config.html);
  92. G.attr('content.test','test');
  93. }).not.toThrow();
  94. })
  95. test('$.attr: simple1 html code set attr result should be ok', () => {
  96. const G = $(hc1, config.html);
  97. G.attr('content.test', 'test');
  98. const result = G.node.content.test === 'test';
  99. expect(result).toBeTruthy();
  100. })
  101. test('$.attr: simple1 html code set attr result should be ok', () => {
  102. const result = $(`<div v-model="a"></div>`, config.html)
  103. .find(`<$_$1 v-model="$_$2"></$_$1>`)
  104. .each(item => {
  105. item.attr('content.attributes').push({
  106. key: { type: "token:attribute-key", content: 'newAttr'},
  107. value: { type: 'token:attribute-value', content: '1'}
  108. })
  109. })
  110. .root()
  111. .generate()
  112. expect(result.match('newAttr')).toBeTruthy();
  113. })