-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for app-config useCourseSearchRecentsScreen
- add @testing-library/react-native - test out prod enabled vs dev enabled for app-config flag
- Loading branch information
Showing
3 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
modules/app-config/__tests__/useCourseSearchRecentsScreen.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,63 @@ | ||
import React, {ReactElement} from 'react' | ||
import {describe, expect, test} from '@jest/globals' | ||
import {renderHook, waitFor} from '@testing-library/react-native' | ||
import {QueryClient, QueryClientProvider} from '@tanstack/react-query' | ||
import {useCourseSearchRecentsScreen} from '../index' | ||
|
||
jest.mock('../../../source/lib/storage', () => ({ | ||
getFeatureFlag: jest.fn(), | ||
})) | ||
|
||
jest.mock('@frogpond/constants', () => ({ | ||
isDevMode: jest.fn(), | ||
})) | ||
|
||
describe('useCourseSearchRecentsScreen', () => { | ||
let queryClient: QueryClient | ||
|
||
beforeAll(() => { | ||
queryClient = new QueryClient() | ||
}) | ||
|
||
afterAll(() => { | ||
queryClient.clear() | ||
queryClient.removeQueries() | ||
}) | ||
|
||
const queryWrapper = ({children}: {children: ReactElement}) => ( | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
) | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const isDevModeMock = require('@frogpond/constants').isDevMode | ||
|
||
const getFeatureFlagMock = | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require('../../../source/lib/storage').getFeatureFlag | ||
|
||
test('it should return true in dev when feature is enabled', async () => { | ||
isDevModeMock.mockReturnValue(true) | ||
getFeatureFlagMock.mockReturnValue(true) | ||
|
||
const {result} = renderHook(() => useCourseSearchRecentsScreen(), { | ||
wrapper: queryWrapper, | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(result.current).toBe(true) | ||
}) | ||
}) | ||
|
||
test('it should return false in prod when feature is enabled', async () => { | ||
isDevModeMock.mockReturnValue(false) | ||
getFeatureFlagMock.mockReturnValue(true) | ||
|
||
const {result} = renderHook(() => useCourseSearchRecentsScreen(), { | ||
wrapper: queryWrapper, | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(result.current).toBe(false) | ||
}) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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