Basically like this:
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 } })