-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #206 from mash-up-kr/release/v1.1.0
Main Release/v1.1.0
- Loading branch information
Showing
10 changed files
with
208 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { act } from '@testing-library/react'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
|
||
import useHistory from './useHistory'; | ||
|
||
const mockNavigate = jest.fn(); | ||
|
||
const mockUseLocation = jest.fn().mockImplementation(() => ({ state: {} })); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
useLocation: () => mockUseLocation(), | ||
useNavigate: jest.fn().mockImplementation(() => mockNavigate), | ||
})); | ||
|
||
describe('useHistory', () => { | ||
it('from 값이 존재한다면 뒤로가기 클릭 시 from으로 이동한다', () => { | ||
// Given | ||
const from = 'from'; | ||
mockUseLocation.mockReturnValueOnce({ | ||
state: { | ||
from, | ||
}, | ||
}); | ||
|
||
// When | ||
const { result } = renderHook(() => useHistory()); | ||
act(() => result.current.handleGoBack()); | ||
|
||
// Then | ||
expect(mockNavigate).toBeCalledWith(from); | ||
}); | ||
|
||
it('from 값이 존재하지 않고 defaultPath가 있다면 defaultPath로 이동한다', () => { | ||
// Given | ||
const defaultPath = 'default-path'; | ||
|
||
// When | ||
const { result } = renderHook(() => useHistory()); | ||
act(() => result.current.handleGoBack(defaultPath)); | ||
|
||
// Then | ||
expect(mockNavigate).toBeCalledWith(defaultPath); | ||
}); | ||
|
||
it('from 값과 defaultPath값 모두 존재하지 않는다면 뒤로 이동한다', () => { | ||
// Given | ||
|
||
// When | ||
const { result } = renderHook(() => useHistory()); | ||
act(() => result.current.handleGoBack()); | ||
|
||
// Then | ||
expect(mockNavigate).toBeCalledWith(-1); | ||
}); | ||
|
||
it('shouldClearQueryString값이 false라면 from값에 쿼리스트링도 함께 저장된다.', () => { | ||
// Given | ||
const from = '/from'; | ||
const queryString = '?queryString=queryString'; | ||
const fromWithQueryString = `${from}${queryString}`; | ||
const to = '/to'; | ||
|
||
mockUseLocation.mockReturnValueOnce({ | ||
pathname: from, | ||
search: queryString, | ||
}); | ||
|
||
// When | ||
const { result } = renderHook(() => useHistory(false)); | ||
act(() => result.current.handleNavigate(to)); | ||
|
||
// Then | ||
|
||
expect(mockNavigate).toBeCalledWith(to, { state: { from: fromWithQueryString } }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.