attrs.spec.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { getRoot, fireEvent, compileAndExecute } from '../helpers/index'
  2. describe('generate attribute', () => {
  3. it('should be generated', (done) => {
  4. compileAndExecute(`
  5. <div>
  6. <text value="Hello World" style="font-size: 100"></text>
  7. </div>
  8. `).then(instance => {
  9. expect(getRoot(instance)).toEqual({
  10. type: 'div',
  11. children: [{
  12. type: 'text',
  13. style: { fontSize: '100' },
  14. attr: { value: 'Hello World' }
  15. }]
  16. })
  17. done()
  18. }).catch(e => done.fail(e))
  19. })
  20. it('should be updated', (done) => {
  21. compileAndExecute(`
  22. <div @click="foo">
  23. <text :value="x"></text>
  24. </div>
  25. `, `
  26. data: { x: 'Hello World' },
  27. methods: {
  28. foo: function () {
  29. this.x = 'Hello Vue'
  30. }
  31. }
  32. `).then(instance => {
  33. expect(getRoot(instance)).toEqual({
  34. type: 'div',
  35. event: ['click'],
  36. children: [
  37. { type: 'text', attr: { value: 'Hello World' }}
  38. ]
  39. })
  40. fireEvent(instance, '_root', 'click')
  41. return instance
  42. }).then(instance => {
  43. expect(getRoot(instance)).toEqual({
  44. type: 'div',
  45. event: ['click'],
  46. children: [
  47. { type: 'text', attr: { value: 'Hello Vue' }}
  48. ]
  49. })
  50. done()
  51. }).catch(e => done.fail(e))
  52. })
  53. it('should be cleared', (done) => {
  54. compileAndExecute(`
  55. <div @click="foo">
  56. <text :value="x"></text>
  57. </div>
  58. `, `
  59. data: { x: 'Hello World' },
  60. methods: {
  61. foo: function () {
  62. this.x = ''
  63. }
  64. }
  65. `).then(instance => {
  66. expect(getRoot(instance)).toEqual({
  67. type: 'div',
  68. event: ['click'],
  69. children: [
  70. { type: 'text', attr: { value: 'Hello World' }}
  71. ]
  72. })
  73. fireEvent(instance, '_root', 'click')
  74. return instance
  75. }).then(instance => {
  76. expect(getRoot(instance)).toEqual({
  77. type: 'div',
  78. event: ['click'],
  79. children: [
  80. { type: 'text', attr: { value: '' }}
  81. ]
  82. })
  83. done()
  84. })
  85. })
  86. })