import Vue from 'vue' describe('Directive v-once', () => { it('should not rerender component', done => { const vm = new Vue({ template: '
{{ a }}
', data: { a: 'hello' } }).$mount() expect(vm.$el.innerHTML).toBe('hello') vm.a = 'world' waitForUpdate(() => { expect(vm.$el.innerHTML).toBe('hello') }).then(done) }) it('should not rerender self and child component', done => { const vm = new Vue({ template: `
{{ a }}
`, data: { a: 'hello' }, components: { item: { template: '
{{ b }}
', props: ['b'] } } }).$mount() expect(vm.$children.length).toBe(1) expect(vm.$el.innerHTML) .toBe('hello
hello
') vm.a = 'world' waitForUpdate(() => { expect(vm.$el.innerHTML) .toBe('hello
hello
') }).then(done) }) it('should rerender parent but not self', done => { const vm = new Vue({ template: `
{{ a }}
`, data: { a: 'hello' }, components: { item: { template: '
{{ b }}
', props: ['b'] } } }).$mount() expect(vm.$children.length).toBe(1) expect(vm.$el.innerHTML) .toBe('hello
hello
') vm.a = 'world' waitForUpdate(() => { expect(vm.$el.innerHTML) .toBe('world
hello
') }).then(done) }) it('should not rerender static sub nodes', done => { const vm = new Vue({ template: `
{{ a }} {{ suffix }}
`, data: { a: 'hello', suffix: '?' }, components: { item: { template: '
{{ b }}
', props: ['b'] } } }).$mount() expect(vm.$el.innerHTML) .toBe('hello
hello
?') vm.a = 'world' waitForUpdate(() => { expect(vm.$el.innerHTML) .toBe('hello
world
?') vm.suffix = '!' }).then(() => { expect(vm.$el.innerHTML) .toBe('hello
world
!') }).then(done) }) it('should work with v-for', done => { const vm = new Vue({ data: { list: [1, 2, 3] }, template: `
{{i}}
` }).$mount() expect(vm.$el.textContent).toBe('123') vm.list.reverse() waitForUpdate(() => { expect(vm.$el.textContent).toBe('123') }).then(done) }) })