diff --git a/code_style.md b/code_style.md index 6e7289d22e..7ccb248689 100644 --- a/code_style.md +++ b/code_style.md @@ -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