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

Function testInOut

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

Source from the content-addressed store, hash-verified

1052
1053 describe('mode: "in-out"', () => {
1054 async function testInOut(
1055 {
1056 trueBranch,
1057 falseBranch,
1058 trueSerialized,
1059 falseSerialized,
1060 }: ToggleOptions,
1061 withKeepAlive = false,
1062 ) {
1063 const toggle = ref(true)
1064 const { props, cbs } = mockProps({ mode: 'in-out' }, withKeepAlive)
1065 const { root } = mount(
1066 props,
1067 () => (toggle.value ? trueBranch() : falseBranch()),
1068 withKeepAlive,
1069 )
1070
1071 toggle.value = false
1072 await nextTick()
1073 expect(serializeInner(root)).toBe(`${trueSerialized}${falseSerialized}`)
1074 // enter should start
1075 expect(props.onBeforeEnter).toHaveBeenCalledTimes(1)
1076 assertCalledWithEl(props.onBeforeEnter, falseSerialized)
1077 expect(props.onEnter).toHaveBeenCalledTimes(1)
1078 assertCalledWithEl(props.onEnter, falseSerialized)
1079 expect(props.onAfterEnter).not.toHaveBeenCalled()
1080 // leave should not start
1081 expect(props.onBeforeLeave).not.toHaveBeenCalled()
1082 expect(props.onLeave).not.toHaveBeenCalled()
1083 expect(props.onAfterLeave).not.toHaveBeenCalled()
1084
1085 // finish enter
1086 cbs.doneEnter[falseSerialized]()
1087 expect(props.onAfterEnter).toHaveBeenCalledTimes(1)
1088 assertCalledWithEl(props.onAfterEnter, falseSerialized)
1089
1090 // leave should start now
1091 expect(props.onBeforeLeave).toHaveBeenCalledTimes(1)
1092 assertCalledWithEl(props.onBeforeLeave, trueSerialized)
1093 expect(props.onLeave).toHaveBeenCalledTimes(1)
1094 assertCalledWithEl(props.onLeave, trueSerialized)
1095 expect(props.onAfterLeave).not.toHaveBeenCalled()
1096 // finish leave
1097 cbs.doneLeave[trueSerialized]()
1098 expect(props.onAfterLeave).toHaveBeenCalledTimes(1)
1099 assertCalledWithEl(props.onAfterLeave, trueSerialized)
1100
1101 // toggle again
1102 toggle.value = true
1103 await nextTick()
1104 expect(serializeInner(root)).toBe(`${falseSerialized}${trueSerialized}`)
1105 // enter should start
1106 expect(props.onBeforeEnter).toHaveBeenCalledTimes(2)
1107 assertCalledWithEl(props.onBeforeEnter, trueSerialized, 1)
1108 expect(props.onEnter).toHaveBeenCalledTimes(2)
1109 assertCalledWithEl(props.onEnter, trueSerialized, 1)
1110 expect(props.onAfterEnter).toHaveBeenCalledTimes(1)
1111 // leave should not start

Callers

nothing calls this directly

Calls 7

serializeInnerFunction · 0.90
mockPropsFunction · 0.85
assertCalledWithElFunction · 0.85
assertCallsFunction · 0.85
mountFunction · 0.70
refFunction · 0.50
nextTickFunction · 0.50

Tested by

no test coverage detected