happy-postman-12006
11/02/2023, 10:34 AMrhythmic-agent-34208
11/02/2023, 10:34 AMfresh-football-47124
happy-postman-12006
11/02/2023, 12:41 PMsetFeatures()
as I need them for my specific test cases.import {
FeatureDefinition,
GrowthBook,
GrowthBookProvider,
} from '@growthbook/growthbook-react'
type FeaturesClient = GrowthBook<Record<string, unknown>> & {
patchFeatures: (features: Record<string, FeatureDefinition<unknown>>) => void
}
export const featuresClient: FeaturesClient = Object.assign(
createFeaturesClient({
apiHost: '',
clientKey: '',
enableDevMode: false,
subscribeToChanges: false,
features: {},
}),
{
patchFeatures(features: Record<string, FeatureDefinition<unknown>>) {
featuresClient.setFeatures({
...featuresClient.getFeatures(),
...features,
})
},
}
)
export const FeaturesProviderMock = ({
children,
}: {
children: React.ReactNode
}) => {
return (
<GrowthBookProvider growthbook={featuresClient}>
{children}
</GrowthBookProvider>
)
}
The createFeaturesClient
function is a small wrapper around new GrowthBook()
.
From my tests, I can then call featuresClient.patchFeatures({ 'feature-name': { defaultValue: true } })
rhythmic-agent-34208
11/03/2023, 12:34 AMhappy-postman-12006
11/03/2023, 8:07 AMrhythmic-agent-34208
11/03/2023, 3:44 PMhappy-postman-12006
11/06/2023, 8:19 AM