(
{
trueBranch,
falseBranch,
trueSerialized,
falseSerialized,
}: ToggleOptions,
withKeepAlive = false,
)
| 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) |
nothing calls this directly
no test coverage detected