Skip to content

Commit 0192390

Browse files
committed
update tests to target devmode
1 parent 25867c3 commit 0192390

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

modules/app-config/__tests__/useCourseSearchRecentsScreen.test.tsx

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ import React, {ReactElement} from 'react'
22
import {describe, expect, test} from '@jest/globals'
33
import {renderHook, waitFor} from '@testing-library/react-native'
44
import {QueryClient, QueryClientProvider} from '@tanstack/react-query'
5-
import {useCourseSearchRecentsScreen} from '../index'
65

7-
jest.mock('../../../source/lib/storage', () => ({
8-
getFeatureFlag: jest.fn(),
9-
}))
6+
import {useFeature} from '../index'
7+
import {AppConfigType} from '../types'
108

11-
jest.mock('@frogpond/constants', () => ({
9+
jest.mock('../../../modules/constants', () => ({
1210
isDevMode: jest.fn(),
1311
}))
1412

13+
jest.mock('../../../source/lib/storage', () => ({
14+
getFeatureFlag: jest.fn(),
15+
}))
16+
1517
describe('useCourseSearchRecentsScreen', () => {
1618
let queryClient: QueryClient
1719

@@ -29,8 +31,7 @@ describe('useCourseSearchRecentsScreen', () => {
2931
)
3032

3133
// eslint-disable-next-line @typescript-eslint/no-var-requires
32-
const isDevModeMock = require('@frogpond/constants').isDevMode
33-
34+
const isDevModeMock = require('../../../modules/constants').isDevMode
3435
const getFeatureFlagMock =
3536
// eslint-disable-next-line @typescript-eslint/no-var-requires
3637
require('../../../source/lib/storage').getFeatureFlag
@@ -39,22 +40,28 @@ describe('useCourseSearchRecentsScreen', () => {
3940
isDevModeMock.mockReturnValue(true)
4041
getFeatureFlagMock.mockReturnValue(true)
4142

42-
const {result} = renderHook(() => useCourseSearchRecentsScreen(), {
43-
wrapper: queryWrapper,
44-
})
43+
const {result} = renderHook(
44+
() => useFeature(AppConfigType.Courses_ShowRecentSearchScreen),
45+
{
46+
wrapper: queryWrapper,
47+
},
48+
)
4549

4650
await waitFor(() => {
4751
expect(result.current).toBe(true)
4852
})
4953
})
5054

51-
test('it should return false in prod when feature is enabled', async () => {
52-
isDevModeMock.mockReturnValue(false)
53-
getFeatureFlagMock.mockReturnValue(true)
55+
test('it should return false in dev when feature is disabled', async () => {
56+
isDevModeMock.mockReturnValue(true)
57+
getFeatureFlagMock.mockReturnValue(false)
5458

55-
const {result} = renderHook(() => useCourseSearchRecentsScreen(), {
56-
wrapper: queryWrapper,
57-
})
59+
const {result} = renderHook(
60+
() => useFeature(AppConfigType.Courses_ShowRecentSearchScreen),
61+
{
62+
wrapper: queryWrapper,
63+
},
64+
)
5865

5966
await waitFor(() => {
6067
expect(result.current).toBe(false)

modules/app-config/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {isDevMode} from '@frogpond/constants'
66
export type {AppConfigType, FeatureFlagType} from './types'
77

88
// helper method to query exported __DEV__ feature flags
9-
const useFeature = (featureKey: AppConfigType): boolean => {
9+
export const useFeature = (featureKey: AppConfigType): boolean => {
1010
let {data: featureValue = false} = useQuery({
1111
queryKey: ['app', 'app:feature-flag', featureKey],
1212
queryFn: () => getFeatureFlag(featureKey),

0 commit comments

Comments
 (0)