From d821323e5cb5f57231b91cdc7887c249ec522ec9 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Mon, 27 Mar 2023 19:03:17 +0100 Subject: [PATCH] Prevent rust-crypto setting from leaking to other tests (#10464) Follow-up to #9759. Because the MatrixClientPeg pushes the use_rust_crypto setting back into the SettingsStore, the setting was leaking out to other tests despite getValue's mock being restored. The solution is to mock out setValue as well. --- test/MatrixClientPeg-test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/MatrixClientPeg-test.ts b/test/MatrixClientPeg-test.ts index 5608b803d6..fb110bd9bf 100644 --- a/test/MatrixClientPeg-test.ts +++ b/test/MatrixClientPeg-test.ts @@ -20,6 +20,7 @@ import fetchMockJest from "fetch-mock-jest"; import { advanceDateAndTime, stubClient } from "./test-utils"; import { IMatrixClientPeg, MatrixClientPeg as peg } from "../src/MatrixClientPeg"; import SettingsStore from "../src/settings/SettingsStore"; +import { SettingLevel } from "../src/settings/SettingLevel"; jest.useFakeTimers(); @@ -121,12 +122,17 @@ describe("MatrixClientPeg", () => { }, ); + const mockSetValue = jest.spyOn(SettingsStore, "setValue").mockResolvedValue(undefined); + const mockInitCrypto = jest.spyOn(testPeg.get(), "initCrypto").mockResolvedValue(undefined); const mockInitRustCrypto = jest.spyOn(testPeg.get(), "initRustCrypto").mockResolvedValue(undefined); await testPeg.start(); expect(mockInitCrypto).not.toHaveBeenCalled(); expect(mockInitRustCrypto).toHaveBeenCalledTimes(1); + + // we should have stashed the setting in the settings store + expect(mockSetValue).toHaveBeenCalledWith("feature_rust_crypto", null, SettingLevel.DEVICE, true); }); }); });