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') done() }).catch(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
') done() }).catch(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
') done() }).catch(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
!') done() }).catch(done) }) })