Skip to content

Commit

Permalink
Update code snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLin0991 committed Jan 26, 2024
1 parent 3808655 commit 11135db
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions docs/technical-design/launch-darkly-testing-approach.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,13 @@ The two important functions in the `ldCientMock` are `variation` and `allFlags`.
```javascript
const ldClientMock = (featureFlags: FeatureFlagSettings): LDClient => ({
... other functions,
variation: jest.fn((
flag: FeatureFlagLDConstant,
defaultValue: FlagValue | undefined
) => {
if (
featureFlags[flag] === undefined &&
defaultValue === undefined
) {
//ldClient.variation doesn't require a default value, throwing error here if a defaultValue was not provided.
throw new Error(
'ldUseClientSpy returned an invalid value of undefined'
)
}
return featureFlags[flag] === undefined
? defaultValue
: featureFlags[flag]
}),
allFlags: jest.fn(() => {
const defaultFeatureFlags = getDefaultFeatureFlags()
Object.assign(defaultFeatureFlags, featureFlags)
return defaultFeatureFlags
}),
variation: jest.fn(
(
flag: FeatureFlagLDConstant,
defaultValue: FlagValue | undefined
) => featureFlags[flag] ?? defaultValue
),
allFlags: jest.fn(() => featureFlags),
})
```
Expand Down

0 comments on commit 11135db

Please sign in to comment.