| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import { getRoot, fireEvent, compileAndExecute } from '../helpers/index'
- describe('generate class', () => {
- it('should be generated', () => {
- compileAndExecute(`
- <div>
- <text class="a b c">Hello World</text>
- </div>
- `, `
- style: {
- a: { fontSize: '100' },
- b: { color: '#ff0000' },
- c: { fontWeight: 'bold' }
- }
- `).then(instance => {
- expect(getRoot(instance)).toEqual({
- type: 'div',
- children: [{
- type: 'text',
- classList: ['a', 'b', 'c'],
- attr: { value: 'Hello World' }
- }]
- })
- })
- })
- it('should be updated', (done) => {
- compileAndExecute(`
- <div @click="foo">
- <text :class="['a', x]">Hello World</text>
- </div>
- `, `
- data: { x: 'b' },
- style: {
- a: { fontSize: '100' },
- b: { color: '#ff0000' },
- c: { fontWeight: 'bold' },
- d: {
- color: '#0000ff',
- fontWeight: 'bold'
- }
- },
- methods: {
- foo: function () {
- this.x = 'd'
- }
- }
- `).then(instance => {
- expect(getRoot(instance)).toEqual({
- type: 'div',
- event: ['click'],
- children: [{
- type: 'text',
- classList: ['a', 'b'],
- attr: { value: 'Hello World' }
- }]
- })
- fireEvent(instance, '_root', 'click')
- return instance
- }).then(instance => {
- expect(getRoot(instance)).toEqual({
- type: 'div',
- event: ['click'],
- children: [{
- type: 'text',
- classList: ['a', 'd'],
- attr: { value: 'Hello World' }
- }]
- })
- done()
- })
- })
- it('should be applied in order', (done) => {
- compileAndExecute(`
- <div @click="foo">
- <text :class="arr">Hello World</text>
- </div>
- `, `
- data: {
- arr: ['b', 'a']
- },
- style: {
- a: { color: '#ff0000' },
- b: { color: '#00ff00' },
- c: { color: '#0000ff' }
- },
- methods: {
- foo: function () {
- this.arr.push('c')
- }
- }
- `).then(instance => {
- expect(getRoot(instance)).toEqual({
- type: 'div',
- event: ['click'],
- children: [{
- type: 'text',
- classList: ['b', 'a'],
- attr: { value: 'Hello World' }
- }]
- })
- fireEvent(instance, '_root', 'click')
- return instance
- }).then(instance => {
- expect(getRoot(instance)).toEqual({
- type: 'div',
- event: ['click'],
- children: [{
- type: 'text',
- classList: ['b', 'a', 'c'],
- attr: { value: 'Hello World' }
- }]
- })
- done()
- })
- })
- it('should be cleared', (done) => {
- compileAndExecute(`
- <div @click="foo">
- <text :class="['a', x]">Hello World</text>
- </div>
- `, `
- data: { x: 'b' },
- style: {
- a: { fontSize: '100' },
- b: { color: '#ff0000' },
- c: { fontWeight: 'bold' }
- },
- methods: {
- foo: function () {
- this.x = 'c'
- }
- }
- `).then(instance => {
- expect(getRoot(instance)).toEqual({
- type: 'div',
- event: ['click'],
- children: [{
- type: 'text',
- classList: ['a', 'b'],
- attr: { value: 'Hello World' }
- }]
- })
- fireEvent(instance, '_root', 'click')
- return instance
- }).then(instance => {
- expect(getRoot(instance)).toEqual({
- type: 'div',
- event: ['click'],
- children: [{
- type: 'text',
- classList: ['a', 'c'],
- attr: { value: 'Hello World' }
- }]
- })
- done()
- })
- })
- })
|