From b47bdc1f1ec60e52b392cc45475b43b9f5cbd4ba Mon Sep 17 00:00:00 2001 From: Clzzi Date: Sun, 14 Nov 2021 17:12:11 +0900 Subject: [PATCH] :white_check_mark: Add: useLogin TEST MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit useLogin Hooks에서 로그인 성공해서 location이 바뀌는것을 테스트 --- __mocks__/handlers.ts | 2 +- hooks/header/useHeader.test.tsx | 4 ++-- hooks/login/useLogin.test.tsx | 12 ++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 hooks/login/useLogin.test.tsx diff --git a/__mocks__/handlers.ts b/__mocks__/handlers.ts index c015370..60c63fe 100644 --- a/__mocks__/handlers.ts +++ b/__mocks__/handlers.ts @@ -8,7 +8,7 @@ import { const handlers = [ // auth - rest.get('/auth/login', (req, res, ctx) => { + rest.post('http://localhost/undefined/auth/login', (req, res, ctx) => { return res(ctx.status(200), ctx.json(MOCK_TOKEN)); }), diff --git a/hooks/header/useHeader.test.tsx b/hooks/header/useHeader.test.tsx index c765595..5eb6b37 100644 --- a/hooks/header/useHeader.test.tsx +++ b/hooks/header/useHeader.test.tsx @@ -8,9 +8,9 @@ describe('useHeader Testing', () => { }); it('Return Value Correctly', async () => { const { result, waitForNextUpdate } = customRenderHook(() => useHeader()); - await waitForNextUpdate(); + await waitForNextUpdate({ timeout: 4000 }); expect(result.current.userId).toEqual(['손민재', 'USER']); - await waitForNextUpdate(); + await waitForNextUpdate({ timeout: 4000 }); expect(result.current.user).toEqual(MOCK_INFO.data); expect(result.current.isMyAccount).toEqual(true); }); diff --git a/hooks/login/useLogin.test.tsx b/hooks/login/useLogin.test.tsx new file mode 100644 index 0000000..d6d79fe --- /dev/null +++ b/hooks/login/useLogin.test.tsx @@ -0,0 +1,12 @@ +import useLogin from './useLogin'; +import { customRenderHook } from 'util/customRenderHook'; + +describe('useLogin Testing', () => { + it('Do Login and Location Change', async () => { + const { result, waitFor } = customRenderHook(() => useLogin()); + await waitFor(() => { + result.current.login('TESTING_CODE'); + }); + expect(window.location.href).toEqual('http://localhost/'); + }); +});