| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import { getRoot, fireEvent, compileAndExecute } from '../helpers/index'
- describe('generate attribute', () => {
- it('should be generated', (done) => {
- compileAndExecute(`
- <div>
- <text value="Hello World" style="font-size: 100"></text>
- </div>
- `).then(instance => {
- expect(getRoot(instance)).toEqual({
- type: 'div',
- children: [{
- type: 'text',
- style: { fontSize: '100' },
- attr: { value: 'Hello World' }
- }]
- })
- done()
- }).catch(e => done.fail(e))
- })
- it('should be updated', (done) => {
- compileAndExecute(`
- <div @click="foo">
- <text :value="x"></text>
- </div>
- `, `
- data: { x: 'Hello World' },
- methods: {
- foo: function () {
- this.x = 'Hello Vue'
- }
- }
- `).then(instance => {
- expect(getRoot(instance)).toEqual({
- type: 'div',
- event: ['click'],
- children: [
- { type: 'text', attr: { value: 'Hello World' }}
- ]
- })
- fireEvent(instance, '_root', 'click')
- return instance
- }).then(instance => {
- expect(getRoot(instance)).toEqual({
- type: 'div',
- event: ['click'],
- children: [
- { type: 'text', attr: { value: 'Hello Vue' }}
- ]
- })
- done()
- }).catch(e => done.fail(e))
- })
- it('should be cleared', (done) => {
- compileAndExecute(`
- <div @click="foo">
- <text :value="x"></text>
- </div>
- `, `
- data: { x: 'Hello World' },
- methods: {
- foo: function () {
- this.x = ''
- }
- }
- `).then(instance => {
- expect(getRoot(instance)).toEqual({
- type: 'div',
- event: ['click'],
- children: [
- { type: 'text', attr: { value: 'Hello World' }}
- ]
- })
- fireEvent(instance, '_root', 'click')
- return instance
- }).then(instance => {
- expect(getRoot(instance)).toEqual({
- type: 'div',
- event: ['click'],
- children: [
- { type: 'text', attr: { value: '' }}
- ]
- })
- done()
- })
- })
- })
|