import Vue from 'vue' describe('Directive v-once', () => { it('should not rerender component', done => { const vm = new Vue({ el: '#app', template: '
{{ a }}
', data: { a: 'hello' } }) expect(vm.$el.innerHTML).toBe('hello') vm.a = 'world' waitForUpdate(() => { expect(vm.$el.innerHTML).toBe('hello') done() }).catch(done) }) it('should not rerender self and child component', done => { const vm = new Vue({ el: '#app', template: `
{{ a }}
`, data: { a: 'hello' }, components: { item: { template: '
{{ b }}
', props: ['b'] } } }) expect(vm.$children.length).toBe(0) expect(vm.$el.innerHTML) .toBe('hello
hello
') vm.a = 'world' waitForUpdate(() => { expect(vm.$el.innerHTML) .toBe('hello
hello
') done() }).catch(done) }) it('should rerender parent but not self', done => { const vm = new Vue({ el: '#app', template: `
{{ a }}
`, data: { a: 'hello' }, components: { item: { template: '
{{ b }}
', props: ['b'] } } }) expect(vm.$children.length).toBe(0) expect(vm.$el.innerHTML) .toBe('hello
hello
') vm.a = 'world' waitForUpdate(() => { expect(vm.$el.innerHTML) .toBe('world
hello
') done() }).catch(done) }) it('should not rerender static sub nodes', done => { const vm = new Vue({ el: '#app', template: `
{{ a }} {{ suffix }}
`, data: { a: 'hello', suffix: '?' }, components: { item: { template: '
{{ b }}
', props: ['b'] } } }) 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
!') done() }).catch(done) }) })