Skip to content

Commit

Permalink
✅ Add: useLogin TEST
Browse files Browse the repository at this point in the history
useLogin Hooks에서 로그인 성공해서 location이 바뀌는것을 테스트
  • Loading branch information
Clzzi committed Nov 14, 2021
1 parent ea7c54e commit b47bdc1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion __mocks__/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}),

Expand Down
4 changes: 2 additions & 2 deletions hooks/header/useHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
12 changes: 12 additions & 0 deletions hooks/login/useLogin.test.tsx
Original file line number Diff line number Diff line change
@@ -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/');
});
});

0 comments on commit b47bdc1

Please sign in to comment.