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
When writing tests that cover code with flags, you can toggle flags on/off programmatically to test the different behavior.
501
+
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.
502
502
503
503
`reflag.ts`:
504
504
505
505
```typescript
506
506
import { ReflagClient } from"@reflag/node-sdk";
507
507
508
-
exportconst reflag =newReflagClient();
508
+
exportconst reflag =newReflagClient({
509
+
offline: true,
510
+
});
511
+
```
512
+
513
+
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()`:
514
+
515
+
```typescript
516
+
// pass directly in the constructor
517
+
const client =newReflagClient({
518
+
offline: true,
519
+
flagOverrides: { myFlag: true },
520
+
});
521
+
522
+
// or replace the base overrides at a later time
523
+
client.setFlagOverrides({ myFlag: false });
524
+
525
+
// clear only the base overrides
526
+
client.clearFlagOverrides();
509
527
```
510
528
511
529
`app.test.ts`:
@@ -520,9 +538,9 @@ afterEach(() => {
520
538
521
539
describe("API Tests", () => {
522
540
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:
553
+
554
+
```typescript
555
+
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:
602
+
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.
603
+
604
+
For automated tests, see the [Testing](#testing) section above.
605
+
606
+
When testing locally during development, you also have these additional ways to provide overrides:
0 commit comments