h,
nextTick,
nodeOps,
+ onUnmounted,
ref,
render,
serialize,
test('w/ KeepAlive', async () => {
await runTestWithKeepAlive(testOutIn)
})
+
+ test('w/ KeepAlive + unmount innerChild', async () => {
+ const unmountSpy = vi.fn()
+ const includeRef = ref(['TrueBranch'])
+ const trueComp = {
+ name: 'TrueBranch',
+ setup() {
+ onUnmounted(unmountSpy)
+ const count = ref(0)
+ return () => h('div', count.value)
+ },
+ }
+
+ const toggle = ref(true)
+ const { props } = mockProps({ mode: 'out-in' }, true /*withKeepAlive*/)
+ const root = nodeOps.createElement('div')
+ const App = {
+ render() {
+ return h(BaseTransition, props, () => {
+ return h(
+ KeepAlive,
+ { include: includeRef.value },
+ toggle.value ? h(trueComp) : h('div'),
+ )
+ })
+ },
+ }
+ render(h(App), root)
+
+ // trigger toggle
+ toggle.value = false
+ includeRef.value = []
+
+ await nextTick()
+ expect(unmountSpy).toHaveBeenCalledTimes(1)
+ })
})
// #6835