You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 63f5b25
Browse filesBrowse the repository at this point in the historyBrowse files
When writing tests that cover code with flags, you can toggle flags on/off programmatically to test the different behavior.
643
+
When writing tests that cover code with flags, you can toggle flags on/off programmatically to test different behavior. For tests, you will often want to run the client in offline mode and provide flag overrides directly through the client options.
644
644
645
645
`reflag.ts`:
646
646
647
647
```typescript
648
648
import { ReflagClient } from"@reflag/node-sdk";
649
649
650
-
exportconst reflag =newReflagClient();
650
+
exportconst reflag =newReflagClient({
651
+
offline: true,
652
+
});
653
+
```
654
+
655
+
You can then set base overrides for a test run by passing `flagOverrides` in the constructor, replacing them later with `setFlagOverrides()`, or clearing them with `clearFlagOverrides()`:
656
+
657
+
```typescript
658
+
// pass directly in the constructor
659
+
const client =newReflagClient({
660
+
offline: true,
661
+
flagOverrides: { myFlag: true },
662
+
});
663
+
664
+
// or replace the base overrides at a later time
665
+
client.setFlagOverrides({ myFlag: false });
666
+
667
+
// clear only the base overrides
668
+
client.clearFlagOverrides();
651
669
```
652
670
653
671
`app.test.ts`:
@@ -662,9 +680,9 @@ afterEach(() => {
662
680
663
681
describe("API Tests", () => {
664
682
it("should return 200 for the root endpoint", async () => {
`pushFlagOverrides()` serves a different purpose: it adds a temporary layer on top of the base overrides and returns a remove function that removes only that layer. This is useful for nested tests:
695
+
696
+
```typescript
697
+
exportconst flag =function (name:string, enabled:boolean):void {
Flag overrides allow you to override flags and their configurations locally. This is particularly useful for development and testing. You can specify overrides in three ways:
744
+
Flag overrides allow you to override flags and their configurations locally. This is particularly useful when testing changes locally, for example when running your app and clicking around to verify behavior before deploying your changes.
745
+
746
+
For automated tests, see the [Testing](#testing) section above.
747
+
748
+
When testing locally during development, you also have these additional ways to provide overrides:
0 commit comments