fix(keep-alive): fix activated hook invocation on nested components (#1743)

fix #1742
This commit is contained in:
zhangzhonghe
2020-08-06 21:42:52 +08:00
committed by GitHub
parent 00683fce9a
commit 233d191d0d
2 changed files with 34 additions and 1 deletions

View File

@@ -165,6 +165,36 @@ describe('KeepAlive', () => {
assertHookCalls(two, [1, 1, 2, 2, 0])
})
// #1742
test('should call lifecycle hooks on nested components when root component no hooks', async () => {
const two = {
name: 'two',
data: () => ({ msg: 'two' }),
render(this: any) {
return h('div', this.msg)
},
activated: jest.fn()
}
const one = {
name: 'one',
data: () => ({ msg: 'one' }),
render(this: any) {
return h(two)
}
}
const toggle = ref(true)
const App = {
render() {
return h(KeepAlive, () => (toggle.value ? h(one) : null))
}
}
render(h(App), root)
expect(serializeInner(root)).toBe(`<div>two</div>`)
expect(two.activated).toHaveBeenCalledTimes(1)
})
test('should call correct hooks for nested keep-alive', async () => {
const toggle2 = ref(true)
one.render = () => h(KeepAlive, () => (toggle2.value ? h(two) : null))