Add better onboard testing (#4007)

This commit is contained in:
Paul Frazee 2024-05-13 20:23:31 -07:00 committed by GitHub
parent fd704bfd44
commit 107760d551
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 71 additions and 1 deletions

View file

@ -130,6 +130,28 @@ export function useGate(): (gateName: Gate) => boolean {
return gate
}
/**
* Debugging tool to override a gate. USE ONLY IN E2E TESTS!
*/
export function useDangerousSetGate(): (
gateName: Gate,
value: boolean,
) => void {
const cache = React.useContext(GateCache)
if (!cache) {
throw Error(
'useDangerousSetGate() cannot be called outside StatsigProvider.',
)
}
const dangerousSetGate = React.useCallback(
(gateName: Gate, value: boolean) => {
cache.set(gateName, value)
},
[cache],
)
return dangerousSetGate
}
function toStatsigUser(did: string | undefined): StatsigUser {
let userID: string | undefined
if (did) {