Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of better way to manage flags and mocks #55

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

markpit
Copy link
Contributor

@markpit markpit commented Nov 25, 2024

JIRA link

Change description

Work checklist

  • Tests added where applicable
  • UI changes look good on mobile
  • UI changes meet accessibility criteria

Merge instructions

We are committed to keeping commit history clean, consistent and linear. To achieve this commit should be structured as follows:

<type>[optional scope]: <description>

and contain the following structural elements:

  • fix: a commit that patches a bug in your codebase (this correlates with PATCH in semantic versioning),
  • feat: a commit that introduces a new feature to the codebase (this correlates with MINOR in semantic versioning),
  • BREAKING CHANGE: a commit that has a footer BREAKING CHANGE: introduces a breaking API change (correlating with MAJOR in semantic versioning). A BREAKING CHANGE can be part of commits of any type,
  • types other than fix: and feat: are allowed, for example build:, chore:, ci:, docs:, style:, refactor:, perf:, test:, and others,
  • footers other than BREAKING CHANGE: <description> may be provided.

@markpit markpit marked this pull request as draft November 25, 2024 10:43
"FLAG_2": getEnvironmentValueAsBoolean("FLAG_2")
};

export const hasFeature = (): FeatureFlags => flags;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasFeature() doesn't return a boolean but a list of feature flag boolean values, so that should be reflected in the function name.

jest.mock("../utils/feature.flag");

(hasFeature as jest.Mock).mockReturnValue({
"FLAG_1": false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could have a pre-defined list of all the feature flags somewhere and then just override to set individual ones to true, in specific tests, when required.

@mwestacott
Copy link
Contributor

A couple of comments but this looks like an improved approach over what we did in ROE.

@lduranteau
Copy link
Contributor

There is a simpler way to do it using jest

https://jestjs.io/docs/mock-function-api#jestreplacedsource

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants