mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-05 12:16:53 +02:00
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:
parent
775332b179
commit
9e18645dad
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user