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('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({
el: '#app',
template: `
{{ a }}
`,
data: { a: 'hello' },
components: {
item: {
template: '{{ b }}
',
props: ['b']
}
}
})
expect(vm.$children.length).toBe(0)
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({
el: '#app',
template: `
{{ a }}
{{ suffix }}
`,
data: {
a: 'hello',
suffix: '?'
},
components: {
item: {
template: '{{ b }}
',
props: ['b']
}
}
})
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)
})
})