| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- import {
- compileAndStringify,
- prepareRuntime,
- resetRuntime,
- createInstance
- } from '../helpers/index'
- describe('generate attribute', () => {
- let runtime
- beforeAll(() => {
- runtime = prepareRuntime()
- })
- afterAll(() => {
- resetRuntime()
- runtime = null
- })
- it('should be generated', () => {
- const { render, staticRenderFns } = compileAndStringify(`
- <div>
- <text value="Hello World" style="font-size: 100"></text>
- </div>
- `)
- const instance = createInstance(runtime, `
- new Vue({
- render: ${render},
- staticRenderFns: ${staticRenderFns},
- el: 'body'
- })
- `)
- expect(instance.getRealRoot()).toEqual({
- type: 'div',
- children: [
- { type: 'text', style: { fontSize: '100' }, attr: { value: 'Hello World' }}
- ]
- })
- })
- it('should be updated', (done) => {
- const { render, staticRenderFns } = compileAndStringify(`
- <div @click="foo">
- <text :value="x"></text>
- </div>
- `)
- const instance = createInstance(runtime, `
- new Vue({
- data: {
- x: 'Hello World'
- },
- methods: {
- foo: function () {
- this.x = 'Hello Vue'
- }
- },
- render: ${render},
- staticRenderFns: ${staticRenderFns},
- el: "body"
- })
- `)
- expect(instance.getRealRoot()).toEqual({
- type: 'div',
- event: ['click'],
- children: [
- { type: 'text', attr: { value: 'Hello World' }}
- ]
- })
- instance.$fireEvent(instance.doc.body.ref, 'click', {})
- setTimeout(() => {
- expect(instance.getRealRoot()).toEqual({
- type: 'div',
- event: ['click'],
- children: [
- { type: 'text', attr: { value: 'Hello Vue' }}
- ]
- })
- done()
- })
- })
- it('should be cleared', (done) => {
- const { render, staticRenderFns } = compileAndStringify(`
- <div @click="foo">
- <text :value="x"></text>
- </div>
- `)
- const instance = createInstance(runtime, `
- new Vue({
- data: {
- x: 'Hello World'
- },
- methods: {
- foo: function () {
- this.x = ''
- }
- },
- render: ${render},
- staticRenderFns: ${staticRenderFns},
- el: "body"
- })
- `)
- expect(instance.getRealRoot()).toEqual({
- type: 'div',
- event: ['click'],
- children: [
- { type: 'text', attr: { value: 'Hello World' }}
- ]
- })
- instance.$fireEvent(instance.doc.body.ref, 'click', {})
- setTimeout(() => {
- expect(instance.getRealRoot()).toEqual({
- type: 'div',
- event: ['click'],
- children: [
- { type: 'text', attr: { value: '' }}
- ]
- })
- done()
- })
- })
- })
|