diff --git a/packages/react/src/hooks/useStep/useStep.spec.ts b/packages/react/src/hooks/useStep/useStep.spec.ts index 1ecbe196d..361e25d1e 100644 --- a/packages/react/src/hooks/useStep/useStep.spec.ts +++ b/packages/react/src/hooks/useStep/useStep.spec.ts @@ -21,21 +21,34 @@ describe('useStep', () => { it('다음 단계로 이동하며, action 함수 제공 시 호출해야 합니다.', async () => { const { result } = renderHook(() => useStep({ maxStep: 2 })); + // nextStep await waitFor(() => result.current.goToNextStep()); - expect(result.current.currentStep).toBe(1); - expect(result.current.hasNextStep).toBe(true); + await waitFor(() => { + expect(result.current.currentStep).toBe(1); + expect(result.current.hasNextStep).toBe(true); + }); - await waitFor(() => result.current.goToNextStep(goToNextStepActionMockFn)); + // nextStep with Function + await waitFor(() => { + result.current.goToNextStep(goToNextStepActionMockFn); + }); - expect(result.current.currentStep).toBe(2); - expect(result.current.hasNextStep).toBe(false); - expect(goToNextStepActionMockFn).toBeCalledTimes(1); + await waitFor(() => { + expect(result.current.currentStep).toBe(2); + expect(result.current.hasNextStep).toBe(false); + expect(goToNextStepActionMockFn).toBeCalledTimes(1); + }); - await waitFor(() => result.current.goToNextStep()); + // nextStep + await waitFor(() => { + result.current.goToNextStep(); + }); - expect(result.current.currentStep).toBe(2); - expect(result.current.hasNextStep).toBe(false); + await waitFor(() => { + expect(result.current.currentStep).toBe(2); + expect(result.current.hasNextStep).toBe(false); + }); }); it('이전 단계로 이동하며, action 함수 제공 시 호출해야 합니다.', async () => { @@ -43,21 +56,27 @@ describe('useStep', () => { useStep({ maxStep: 3, initialStep: 2 }) ); + // prevStep await waitFor(() => result.current.goToPrevStep()); + await waitFor(() => { + expect(result.current.currentStep).toBe(1); + expect(result.current.hasPrevStep).toBe(true); + }); - expect(result.current.currentStep).toBe(1); - expect(result.current.hasPrevStep).toBe(true); - + // prevStep with Function await waitFor(() => result.current.goToPrevStep(goToPrevStepActionMockFn)); + await waitFor(() => { + expect(result.current.currentStep).toBe(0); + expect(result.current.hasPrevStep).toBe(false); + expect(goToPrevStepActionMockFn).toBeCalledTimes(1); + }); - expect(result.current.currentStep).toBe(0); - expect(result.current.hasPrevStep).toBe(false); - expect(goToPrevStepActionMockFn).toBeCalledTimes(1); - + // prevStep await waitFor(() => result.current.goToPrevStep()); - - expect(result.current.currentStep).toBe(0); - expect(result.current.hasPrevStep).toBe(false); + await waitFor(() => { + expect(result.current.currentStep).toBe(0); + expect(result.current.hasPrevStep).toBe(false); + }); }); it('infinite 옵션이 true인 경우 무한 루프를 처리해야 합니다.', async () => { @@ -65,25 +84,36 @@ describe('useStep', () => { useStep({ maxStep: 3, infinite: true }) ); + // prevStep await waitFor(() => result.current.goToPrevStep()); + await waitFor(() => { + expect(result.current.currentStep).toBe(3); + }); - expect(result.current.currentStep).toBe(3); - + // prevStep await waitFor(() => result.current.goToPrevStep()); + await waitFor(() => { + expect(result.current.currentStep).toBe(2); + }); - expect(result.current.currentStep).toBe(2); - + // prevStep await waitFor(() => result.current.goToPrevStep()); + await waitFor(() => { + expect(result.current.currentStep).toBe(1); + }); - expect(result.current.currentStep).toBe(1); - + // prevStep await waitFor(() => result.current.goToPrevStep()); - expect(result.current.currentStep).toBe(0); + await waitFor(() => { + expect(result.current.currentStep).toBe(0); + }); + // prevStep await waitFor(() => result.current.goToPrevStep()); - - expect(result.current.currentStep).toBe(3); + await waitFor(() => { + expect(result.current.currentStep).toBe(3); + }); }); it('setStep 함수를 통해 특정 step로 이동하며, action 함수 제공 시 호출해야 합니다.', async () => { @@ -93,16 +123,22 @@ describe('useStep', () => { await waitFor(() => { result.current.setStep(2, setStepActionMockFn); }); - - expect(result.current.currentStep).toBe(2); - expect(setStepActionMockFn).toBeCalledTimes(1); + await waitFor(() => { + expect(result.current.currentStep).toBe(2); + expect(setStepActionMockFn).toBeCalledTimes(1); + }); // setStep Function await waitFor(() => { - result.current.setStep((currentStep) => currentStep + 1); + result.current.setStep( + (currentStep) => currentStep + 1, + setStepActionMockFn + ); + }); + await waitFor(() => { + expect(result.current.currentStep).toBe(3); + expect(setStepActionMockFn).toBeCalledTimes(2); }); - - expect(result.current.currentStep).toBe(3); }); it('초기 step으로 이동해야 하며, action 함수 제공 시 호출해야 합니다.', async () => { @@ -110,18 +146,22 @@ describe('useStep', () => { useStep({ maxStep: 3, initialStep: 2 }) ); + // nextStep await waitFor(() => { result.current.goToNextStep(); }); + await waitFor(() => { + expect(result.current.currentStep).toBe(3); + }); - expect(result.current.currentStep).toBe(3); - + // resetStep await waitFor(() => { result.current.resetStep(resetStepActionMockFn); }); - - expect(result.current.currentStep).toBe(2); - expect(resetStepActionMockFn).toBeCalledTimes(1); + await waitFor(() => { + expect(result.current.currentStep).toBe(2); + expect(resetStepActionMockFn).toBeCalledTimes(1); + }); }); it('유효하지 않은 step 일 시 에러를 던져야 합니다.', async () => {