From 9e18645dad29230b515bafcf7a9481a911a5e54f Mon Sep 17 00:00:00 2001 From: Will Hunt <2072976+Half-Shot@users.noreply.github.com> Date: Tue, 13 Jan 2026 19:16:23 +0000 Subject: [PATCH] CodeStyle: Add a note about SettingsStore mocks This has bitten me a number of times and impacts us *all* over the code. --- code_style.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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