Skip to content

Commit

Permalink
add test for app-config useCourseSearchRecentsScreen
Browse files Browse the repository at this point in the history
- add @testing-library/react-native
- test out prod enabled vs dev enabled for app-config flag
  • Loading branch information
drewvolz committed Oct 19, 2023
1 parent 37a954b commit 25867c3
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 0 deletions.
63 changes: 63 additions & 0 deletions modules/app-config/__tests__/useCourseSearchRecentsScreen.test.tsx
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)
})
})
})
102 changes: 102 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"@jest/globals": "29.6.4",
"@sentry/cli": "2.20.6",
"@tanstack/eslint-plugin-query": "4.34.1",
"@testing-library/react-native": "12.3.0",
"@types/base-64": "1.0.0",
"@types/http-cache-semantics": "4.0.1",
"@types/jest": "29.5.4",
Expand Down

0 comments on commit 25867c3

Please sign in to comment.