import { getRoot, fireEvent, compileAndExecute } from '../helpers/index' describe('generate class', () => { it('should be generated', () => { compileAndExecute(`
Hello World
`, ` 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(`
Hello World
`, ` 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(`
Hello World
`, ` 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(`
Hello World
`, ` 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() }) }) })