MCPcopy
hub / github.com/vuejs/core / testOutIn

Function testOutIn

packages/runtime-core/__tests__/components/BaseTransition.spec.ts:717–806  ·  view source on GitHub ↗
(
      {
        trueBranch,
        falseBranch,
        trueSerialized,
        falseSerialized,
      }: ToggleOptions,
      withKeepAlive = false,
    )

Source from the content-addressed store, hash-verified

715
716 describe('mode: "out-in"', () => {
717 async function testOutIn(
718 {
719 trueBranch,
720 falseBranch,
721 trueSerialized,
722 falseSerialized,
723 }: ToggleOptions,
724 withKeepAlive = false,
725 ) {
726 const toggle = ref(true)
727 const { props, cbs } = mockProps({ mode: 'out-in' }, withKeepAlive)
728 const { root } = mount(
729 props,
730 () => (toggle.value ? trueBranch() : falseBranch()),
731 withKeepAlive,
732 )
733
734 // trigger toggle
735 toggle.value = false
736 await nextTick()
737 // a placeholder is injected until the leave finishes
738 expect(serializeInner(root)).toBe(`${trueSerialized}<!---->`)
739 expect(props.onBeforeLeave).toHaveBeenCalledTimes(1)
740 assertCalledWithEl(props.onBeforeLeave, trueSerialized)
741 expect(props.onLeave).toHaveBeenCalledTimes(1)
742 assertCalledWithEl(props.onLeave, trueSerialized)
743 expect(props.onAfterLeave).not.toHaveBeenCalled()
744 // enter should not have started
745 expect(props.onBeforeEnter).not.toHaveBeenCalled()
746 expect(props.onEnter).not.toHaveBeenCalled()
747 expect(props.onAfterEnter).not.toHaveBeenCalled()
748
749 cbs.doneLeave[trueSerialized]()
750 expect(props.onAfterLeave).toHaveBeenCalledTimes(1)
751 assertCalledWithEl(props.onAfterLeave, trueSerialized)
752 // have to wait for a tick because this triggers an update
753 await nextTick()
754 expect(serializeInner(root)).toBe(falseSerialized)
755 // enter should start
756 expect(props.onBeforeEnter).toHaveBeenCalledTimes(1)
757 assertCalledWithEl(props.onBeforeEnter, falseSerialized)
758 expect(props.onEnter).toHaveBeenCalledTimes(1)
759 assertCalledWithEl(props.onEnter, falseSerialized)
760 expect(props.onAfterEnter).not.toHaveBeenCalled()
761 // finish enter
762 cbs.doneEnter[falseSerialized]()
763 expect(props.onAfterEnter).toHaveBeenCalledTimes(1)
764 assertCalledWithEl(props.onAfterEnter, falseSerialized)
765
766 // toggle again
767 toggle.value = true
768 await nextTick()
769 expect(serializeInner(root)).toBe(`${falseSerialized}<!---->`)
770 expect(props.onBeforeLeave).toHaveBeenCalledTimes(2)
771 assertCalledWithEl(props.onBeforeLeave, falseSerialized, 1)
772 expect(props.onLeave).toHaveBeenCalledTimes(2)
773 assertCalledWithEl(props.onLeave, falseSerialized, 1)
774 expect(props.onAfterLeave).toHaveBeenCalledTimes(1)

Callers

nothing calls this directly

Calls 12

serializeInnerFunction · 0.90
renderFunction · 0.90
serializeFunction · 0.90
mockPropsFunction · 0.85
assertCalledWithElFunction · 0.85
assertCallsFunction · 0.85
hFunction · 0.85
createElementMethod · 0.80
mountFunction · 0.70
unmountFunction · 0.70
refFunction · 0.50
nextTickFunction · 0.50

Tested by

no test coverage detected