Skip to content

test(feature-flags-react-client): add unit tests - #290

Merged
Komoszek merged 1 commit into
mainfrom
test/feature-flags-react-client
Jun 25, 2026
Merged

Komoszek merged 1 commit into
mainfrom
test/feature-flags-react-client

Conversation

@claude

@claude claude Bot commented Jun 25, 2026

Copy link
Copy Markdown

Requested by Sebastian Konowrocki · Slack thread

Before / After

The @leancodepl/feature-flags-react-client package had no tests. It now has 12 tests covering the full public surface of mkFeatureFlags:

  • Provider registration — verifies the supplied OpenFeature provider is registered exactly once via OpenFeature.setProvider.
  • Returned API shape — FeatureFlagsProvider is the OpenFeature React provider; useFeatureFlag / setFeatureFlagsContext are callable.
  • setFeatureFlagsContext — delegates to OpenFeature.setContext and stays bound to OpenFeature after destructuring (the .bind contract).
  • useFeatureFlag — resolves real values from a provider (boolean/number), falls back to the per-flag defaultValue when a flag is missing or disabled, prefers an explicit defaultValue, and respects explicit falsy defaults (false / "") over the nullish-coalescing fallback. Also asserts the stringified key is forwarded to the underlying useFlag.

How

Real InMemoryProvider + OpenFeatureProvider wrapper with @testing-library/react renderHook, exercising actual flag evaluation; vi.spyOn for the OpenFeature registration/context calls and a partial vi.mock of @openfeature/react-sdk to assert the useFlag call shape. Global OpenFeature state is reset between tests for isolation.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DXXPnGepYUGie3we1X9PTR


Generated by Claude Code

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXXPnGepYUGie3we1X9PTR
@claude
claude Bot marked this pull request as ready for review June 25, 2026 09:35
@Komoszek
Komoszek merged commit 3d7278b into main Jun 25, 2026
1 check passed
@Komoszek
Komoszek deleted the test/feature-flags-react-client branch June 25, 2026 12:44
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.

2 participants