From f8f95e5b585d92a9da0127c93d059bc570a59d9a Mon Sep 17 00:00:00 2001 From: loganwc Date: Thu, 9 May 2024 10:19:43 -0500 Subject: [PATCH] FF added jest testing instruction --- .../feature-flags/how-to-use-feature-flags.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/tools/feature-flags/how-to-use-feature-flags.md b/docs/tools/feature-flags/how-to-use-feature-flags.md index 4d71796992f..c19bbdfe29c 100644 --- a/docs/tools/feature-flags/how-to-use-feature-flags.md +++ b/docs/tools/feature-flags/how-to-use-feature-flags.md @@ -246,6 +246,27 @@ export const MyThing = () => { } ``` +## Jest Testing Feature Flags + +```javascript +import { isBooleanFlagEnabled } from 'utils/featureFlags'; +``` + +Add the following block to the top of your test file: + +```javascript +jest.mock('utils/featureFlags', () => ({ + ...jest.requireActual('utils/featureFlags'), + isBooleanFlagEnabled: jest.fn().mockImplementation(() => Promise.resolve(false)), +})); +``` + +You can mock the boolean value in your tests with: + +```javascript +isBooleanFlagEnabled.mockImplementation(() => Promise.resolve(YOUR_BOOLEAN_VALUE_HERE)) +``` + ## Deploying Feature Flags Each deployed environment has its own feature flag configuration. The