2
0

style.spec.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import { getRoot, fireEvent, compileAndExecute } from '../helpers/index'
  2. describe('generate style', () => {
  3. it('should be generated', () => {
  4. compileAndExecute(`
  5. <div>
  6. <text style="font-size: 100">Hello World</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. })
  18. })
  19. it('should be generated by array binding', (done) => {
  20. compileAndExecute(`
  21. <div>
  22. <text :style="[x, y]" @click="foo">Hello {{z}}</text>
  23. </div>
  24. `, `
  25. data: {
  26. x: { fontSize: 100, color: '#00ff00' },
  27. y: { color: '#ff0000', fontWeight: 'bold' },
  28. z: 'World'
  29. },
  30. methods: {
  31. foo: function () {
  32. this.x.fontSize = 200
  33. this.x.color = '#0000ff'
  34. Vue.delete(this.y, 'fontWeight')
  35. this.z = 'Weex'
  36. }
  37. }
  38. `).then(instance => {
  39. expect(getRoot(instance)).toEqual({
  40. type: 'div',
  41. children: [
  42. {
  43. type: 'text',
  44. event: ['click'],
  45. style: { fontSize: 100, color: '#ff0000', fontWeight: 'bold' },
  46. attr: { value: 'Hello World' }
  47. }
  48. ]
  49. })
  50. fireEvent(instance, instance.document.body.children[0].ref, 'click')
  51. return instance
  52. }).then(instance => {
  53. expect(getRoot(instance)).toEqual({
  54. type: 'div',
  55. children: [
  56. {
  57. type: 'text',
  58. event: ['click'],
  59. style: { fontSize: 200, color: '#ff0000', fontWeight: '' },
  60. attr: { value: 'Hello Weex' }
  61. }
  62. ]
  63. })
  64. done()
  65. })
  66. })
  67. it('should be generated by map binding', (done) => {
  68. compileAndExecute(`
  69. <div>
  70. <text :style="{ fontSize: x, color: '#00ff00' }" @click="foo">Hello</text>
  71. <text :style="y">{{z}}</text>
  72. </div>
  73. `, `
  74. data: {
  75. x: 100,
  76. y: { color: '#ff0000', fontWeight: 'bold' },
  77. z: 'World'
  78. },
  79. methods: {
  80. foo: function () {
  81. this.x = 200
  82. this.y.color = '#0000ff'
  83. Vue.delete(this.y, 'fontWeight')
  84. this.z = 'Weex'
  85. }
  86. }
  87. `).then(instance => {
  88. expect(getRoot(instance)).toEqual({
  89. type: 'div',
  90. children: [
  91. {
  92. type: 'text',
  93. event: ['click'],
  94. style: { fontSize: 100, color: '#00ff00' },
  95. attr: { value: 'Hello' }
  96. },
  97. {
  98. type: 'text',
  99. style: { color: '#ff0000', fontWeight: 'bold' },
  100. attr: { value: 'World' }
  101. }
  102. ]
  103. })
  104. fireEvent(instance, instance.document.body.children[0].ref, 'click')
  105. return instance
  106. }).then(instance => {
  107. expect(getRoot(instance)).toEqual({
  108. type: 'div',
  109. children: [
  110. {
  111. type: 'text',
  112. event: ['click'],
  113. style: { fontSize: 200, color: '#00ff00' },
  114. attr: { value: 'Hello' }
  115. },
  116. {
  117. type: 'text',
  118. style: { color: '#0000ff', fontWeight: '' },
  119. attr: { value: 'Weex' }
  120. }
  121. ]
  122. })
  123. done()
  124. })
  125. })
  126. })