CodeStyle: Add a note about SettingsStore mocks

This has bitten me a number of times and impacts us *all* over the code.
This commit is contained in:
Will Hunt 2026-01-13 19:16:23 +00:00 committed by GitHub
parent 775332b179
commit 9e18645dad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -364,6 +364,19 @@ Note: We use PostCSS + some plugins to process our styles. It looks like SCSS, b
});
});
```
3. When you need to test a feature that relies on SettingsStore values, be sure to tighly scope your mock:
```typescript
// BAD - Obscures other settings, not clear which setting is required for test.
jest.spyOn(SettingsStore, "getValue").mockReturnValue(false);
// GOOD - Passes through other settings to SettingsStore, clear which settings are in use.
const realGetValue = SettingsStore.getValue;
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName, ...params) => {
if (settingName === "feature_cool_stuff") {
return true;
}
realGetValue(settingName, ...params);
});
```
## Comments