Skip to content

Commit

Permalink
test: add testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchangtao committed Nov 27, 2024
1 parent a44c5ce commit e2771df
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
49 changes: 49 additions & 0 deletions packages/runtime-core/__tests__/components/BaseTransition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1198,4 +1198,53 @@ describe('BaseTransition', () => {
test('should not error on KeepAlive w/ function children', () => {
expect(() => mount({}, () => () => h('div'), true)).not.toThrow()
})

// #12465
test('mode: "out-in" KeepAlive fallthroughAttrs by PROD', async () => {
__DEV__ = false
async function testOutIn({ trueBranch, falseBranch }: ToggleOptions) {
const toggle = ref(true)
const { props, cbs } = mockProps({ mode: 'out-in' }, true)
const root = nodeOps.createElement('div')
const show = ref(true)
const App = {
render() {
return show.value
? h(
BaseTransition,
{
...props,
class: 'test',
},
h(KeepAlive, null, toggle.value ? trueBranch() : falseBranch()),
)
: null
},
}
render(h(App), root)

expect(serializeInner(root)).toBe(`<div class="test">0</div>`)

// trigger toggle
toggle.value = false
await nextTick()
expect(props.onBeforeLeave).toHaveBeenCalledTimes(1)
expect(serialize((props.onBeforeLeave as any).mock.calls[0][0])).toBe(
`<div class="test">0</div>`,
)
expect(props.onLeave).toHaveBeenCalledTimes(1)
expect(serialize((props.onLeave as any).mock.calls[0][0])).toBe(
`<div class="test">0</div>`,
)
expect(props.onAfterLeave).not.toHaveBeenCalled()
// enter should not have started
expect(props.onBeforeEnter).not.toHaveBeenCalled()
expect(props.onEnter).not.toHaveBeenCalled()
expect(props.onAfterEnter).not.toHaveBeenCalled()
cbs.doneLeave[`<div class="test">0</div>`]()
expect(serializeInner(root)).toBe(`<span class="test">0</span>`)
}
await runTestWithKeepAlive(testOutIn)
__DEV__ = true
})
})
3 changes: 1 addition & 2 deletions packages/runtime-core/src/components/BaseTransition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,7 @@ function getInnerChild(vnode: VNode): VNode | undefined {

return vnode
}
// #7121 ensure get the child component subtree in case
// it's been replaced during HMR
// #7121,#12465 ensure get the child component subtree in case
if (vnode.component) {
return vnode.component.subTree
}
Expand Down

0 comments on commit e2771df

Please sign in to comment.