Skip to content

Commit 25867c3

Browse files
committed
add test for app-config useCourseSearchRecentsScreen
- add @testing-library/react-native - test out prod enabled vs dev enabled for app-config flag
1 parent 37a954b commit 25867c3

File tree

3 files changed

+166
-0
lines changed

3 files changed

+166
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React, {ReactElement} from 'react'
2+
import {describe, expect, test} from '@jest/globals'
3+
import {renderHook, waitFor} from '@testing-library/react-native'
4+
import {QueryClient, QueryClientProvider} from '@tanstack/react-query'
5+
import {useCourseSearchRecentsScreen} from '../index'
6+
7+
jest.mock('../../../source/lib/storage', () => ({
8+
getFeatureFlag: jest.fn(),
9+
}))
10+
11+
jest.mock('@frogpond/constants', () => ({
12+
isDevMode: jest.fn(),
13+
}))
14+
15+
describe('useCourseSearchRecentsScreen', () => {
16+
let queryClient: QueryClient
17+
18+
beforeAll(() => {
19+
queryClient = new QueryClient()
20+
})
21+
22+
afterAll(() => {
23+
queryClient.clear()
24+
queryClient.removeQueries()
25+
})
26+
27+
const queryWrapper = ({children}: {children: ReactElement}) => (
28+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
29+
)
30+
31+
// eslint-disable-next-line @typescript-eslint/no-var-requires
32+
const isDevModeMock = require('@frogpond/constants').isDevMode
33+
34+
const getFeatureFlagMock =
35+
// eslint-disable-next-line @typescript-eslint/no-var-requires
36+
require('../../../source/lib/storage').getFeatureFlag
37+
38+
test('it should return true in dev when feature is enabled', async () => {
39+
isDevModeMock.mockReturnValue(true)
40+
getFeatureFlagMock.mockReturnValue(true)
41+
42+
const {result} = renderHook(() => useCourseSearchRecentsScreen(), {
43+
wrapper: queryWrapper,
44+
})
45+
46+
await waitFor(() => {
47+
expect(result.current).toBe(true)
48+
})
49+
})
50+
51+
test('it should return false in prod when feature is enabled', async () => {
52+
isDevModeMock.mockReturnValue(false)
53+
getFeatureFlagMock.mockReturnValue(true)
54+
55+
const {result} = renderHook(() => useCourseSearchRecentsScreen(), {
56+
wrapper: queryWrapper,
57+
})
58+
59+
await waitFor(() => {
60+
expect(result.current).toBe(false)
61+
})
62+
})
63+
})

package-lock.json

Lines changed: 102 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"@jest/globals": "29.6.4",
114114
"@sentry/cli": "2.20.6",
115115
"@tanstack/eslint-plugin-query": "4.34.1",
116+
"@testing-library/react-native": "12.3.0",
116117
"@types/base-64": "1.0.0",
117118
"@types/http-cache-semantics": "4.0.1",
118119
"@types/jest": "29.5.4",

0 commit comments

Comments
 (0)