From ea7c54ec3c2dd8d93cdca25f339f12aaae1e16ec Mon Sep 17 00:00:00 2001 From: Clzzi Date: Sun, 14 Nov 2021 15:47:03 +0900 Subject: [PATCH] :test_tube: Add: useHeader TEST MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit useHeader Hooks의 userid, user, isMyAccount State에 값이 잘 들어가는지 체크 --- __mocks__/data/users.ts | 2 +- hooks/header/useHeader.test.tsx | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 hooks/header/useHeader.test.tsx diff --git a/__mocks__/data/users.ts b/__mocks__/data/users.ts index 181701a..2b77ada 100644 --- a/__mocks__/data/users.ts +++ b/__mocks__/data/users.ts @@ -16,7 +16,7 @@ export const MOCK_TOTALUSERS: ITotalUserRankResponse = { totalContributions: 2100, user: { id: 'user_id_value', - name: 'Clzzi', + name: '손민재', }, userImage: 'http://test.jpg', }, diff --git a/hooks/header/useHeader.test.tsx b/hooks/header/useHeader.test.tsx new file mode 100644 index 0000000..c765595 --- /dev/null +++ b/hooks/header/useHeader.test.tsx @@ -0,0 +1,17 @@ +import { customRenderHook } from 'util/customRenderHook'; +import { MOCK_INFO } from '__mocks__/data/auth'; +import useHeader from './useHeader'; + +describe('useHeader Testing', () => { + beforeEach(() => { + localStorage.setItem('access_token', 'testToken'); + }); + it('Return Value Correctly', async () => { + const { result, waitForNextUpdate } = customRenderHook(() => useHeader()); + await waitForNextUpdate(); + expect(result.current.userId).toEqual(['손민재', 'USER']); + await waitForNextUpdate(); + expect(result.current.user).toEqual(MOCK_INFO.data); + expect(result.current.isMyAccount).toEqual(true); + }); +});