This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc90d90
commit 5564108
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/components/layout/footer/__tests__/ServerTime.test.tsx
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,11 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import ServerTime from '../ServerTime'; | ||
|
||
jest.mock('Hooks/useServerTime', () => () => 1234567890); | ||
|
||
describe('ServerTime component', () => { | ||
it('should render the component with correct time format', () => { | ||
render(<ServerTime />); | ||
expect(screen.getByText('2009-02-13 23:31:30 GMT')).toBeInTheDocument(); | ||
}); | ||
}); |
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,25 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import useQuery from 'Api/hooks/useQuery'; | ||
import useServerTime from 'Hooks/useServerTime'; | ||
|
||
jest.mock('Api/hooks/useQuery'); | ||
|
||
const mockUseQuery = useQuery as jest.MockedFunction<typeof useQuery>; | ||
|
||
describe('useServerTime hook', () => { | ||
it('should return initial server time and updates it based on the useQuery result', () => { | ||
// @ts-expect-error need to come up with a way to mock the return type of useQuery | ||
mockUseQuery.mockReturnValue({ data: { time: 1234567890 } }); | ||
|
||
const { result } = renderHook(() => useServerTime()); | ||
expect(result.current).toBe(1234567890); | ||
}); | ||
|
||
it('should handle useQuery data being null', () => { | ||
// @ts-expect-error need to come up with a way to mock the return type of useQuery | ||
mockUseQuery.mockReturnValue({ data: { time: null } }); | ||
|
||
const { result } = renderHook(() => useServerTime()); | ||
expect(result.current).toBeGreaterThan(0); | ||
}); | ||
}); |