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('hellohello
')
vm.a = 'world'
waitForUpdate(() => {
expect(vm.$el.innerHTML)
.toBe('hellohello
')
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('hellohello
')
vm.a = 'world'
waitForUpdate(() => {
expect(vm.$el.innerHTML)
.toBe('worldhello
')
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('hellohello
?')
vm.a = 'world'
waitForUpdate(() => {
expect(vm.$el.innerHTML)
.toBe('helloworld
?')
vm.suffix = '!'
}).then(() => {
expect(vm.$el.innerHTML)
.toBe('helloworld
!')
done()
}).catch(done)
})
})