From 5c238b84eb5583dfb734da16317b8709692f80ed Mon Sep 17 00:00:00 2001 From: Mantra Date: Tue, 5 Nov 2024 17:56:38 +0000 Subject: [PATCH] batch of tests --- app/static/tests/mocks.ts | 38 ++--- app/static/tests/testUtils.ts | 2 +- app/static/tests/unit/apiService.test.ts | 84 +++++----- app/static/tests/unit/csvUpload.test.ts | 157 ++++++++---------- app/static/tests/unit/directives/help.test.ts | 10 +- .../tests/unit/directives/tooltip.test.ts | 18 +- app/static/tests/unit/excel/mocks.ts | 12 +- .../excel/wodinModelOutputDownload.test.ts | 16 +- .../wodinSensitivitySummaryDownload.test.ts | 16 +- .../tests/unit/localStorageManager.test.ts | 18 +- app/static/tests/unit/palette.test.ts | 2 +- app/static/tests/unit/plot.test.ts | 2 +- app/static/tests/unit/router.test.ts | 25 +-- app/static/tests/unit/serialiser.test.ts | 78 ++++----- app/static/tests/unit/utils.test.ts | 10 +- 15 files changed, 238 insertions(+), 250 deletions(-) diff --git a/app/static/tests/mocks.ts b/app/static/tests/mocks.ts index 470b462df..867dd0bb5 100644 --- a/app/static/tests/mocks.ts +++ b/app/static/tests/mocks.ts @@ -1,8 +1,8 @@ import MockAdapter from "axios-mock-adapter"; import axios from "axios"; -import { BasicState } from "../src/app/store/basic/state"; -import { FitState } from "../src/app/store/fit/state"; -import { StochasticState } from "../src/app/store/stochastic/state"; +import { BasicState } from "../src/store/basic/state"; +import { FitState } from "../src/store/fit/state"; +import { StochasticState } from "../src/store/stochastic/state"; import { AdvancedOptions, BatchPars, @@ -11,27 +11,27 @@ import { ResponseSuccess, VaryingPar, WodinError -} from "../src/app/types/responseTypes"; -import { ModelState } from "../src/app/store/model/state"; -import { AdvancedComponentType, RunState } from "../src/app/store/run/state"; -import { CodeState } from "../src/app/store/code/state"; -import { FitDataState } from "../src/app/store/fitData/state"; -import { AppType, VisualisationTab } from "../src/app/store/appState/state"; -import { ModelFitState } from "../src/app/store/modelFit/state"; +} from "../src/types/responseTypes"; +import { ModelState } from "../src/store/model/state"; +import { AdvancedComponentType, RunState } from "../src/store/run/state"; +import { CodeState } from "../src/store/code/state"; +import { FitDataState } from "../src/store/fitData/state"; +import { AppType, VisualisationTab } from "../src/store/appState/state"; +import { ModelFitState } from "../src/store/modelFit/state"; import { SensitivityPlotExtreme, SensitivityPlotType, SensitivityScaleType, SensitivityState, SensitivityVariationType -} from "../src/app/store/sensitivity/state"; -import { VersionsState } from "../src/app/store/versions/state"; -import { defaultGraphSettings, GraphsState } from "../src/app/store/graphs/state"; +} from "../src/store/sensitivity/state"; +import { VersionsState } from "../src/store/versions/state"; +import { GraphsState, defaultGraphSettings } from "../src/store/graphs/state"; import { LanguageState } from "../translationPackage/store/state"; -import { Language } from "../src/app/types/languageTypes"; -import { noSensitivityUpdateRequired } from "../src/app/store/sensitivity/sensitivity"; -import { MultiSensitivityState } from "../src/app/store/multiSensitivity/state"; -import { SessionsState } from "../src/app/store/sessions/state"; +import { Language } from "../src/types/languageTypes"; +import { noSensitivityUpdateRequired } from "../src/store/sensitivity/sensitivity"; +import { MultiSensitivityState } from "../src/store/multiSensitivity/state"; +import { SessionsState } from "../src/store/sessions/state"; export const mockAxios = new MockAdapter(axios); @@ -377,12 +377,12 @@ export const mockBatchParsDisplace = ( export const mockRunnerOde = () => { return { - wodinRun: jest.fn((odin, pars, start, end) => "test solution" as any) + wodinRun: vi.fn((odin, pars, start, end) => "test solution" as any) } as any; }; export const mockRunnerDiscrete = () => { return { - wodinRunDiscrete: jest.fn(() => "test discrete result" as any) + wodinRunDiscrete: vi.fn(() => "test discrete result" as any) } as any; }; diff --git a/app/static/tests/testUtils.ts b/app/static/tests/testUtils.ts index c28a0479c..8c28d689f 100644 --- a/app/static/tests/testUtils.ts +++ b/app/static/tests/testUtils.ts @@ -1,5 +1,5 @@ import { VueWrapper } from "@vue/test-utils"; -import WodinPanels from "../src/app/components/WodinPanels.vue"; +import WodinPanels from "../src/components/WodinPanels.vue"; export const fileTimeout = 20; diff --git a/app/static/tests/unit/apiService.test.ts b/app/static/tests/unit/apiService.test.ts index 42798e1ae..66ed9ff7f 100644 --- a/app/static/tests/unit/apiService.test.ts +++ b/app/static/tests/unit/apiService.test.ts @@ -1,7 +1,7 @@ -import { api } from "../../src/app/apiService"; +import { api } from "../../src/apiService"; import { mockAxios, mockError, mockFailure, mockSuccess, mockBasicState } from "../mocks"; -import { freezer } from "../../src/app/utils"; -import Mock = jest.Mock; +import { freezer } from "../../src/utils"; +import { Mock } from "vitest"; const BASE_URL = "http://localhost:3000"; const rootState = mockBasicState({ baseUrl: BASE_URL }); @@ -11,19 +11,19 @@ describe("ApiService", () => { const TEST_BODY = "test body"; beforeEach(() => { - console.log = jest.fn(); - console.warn = jest.fn(); + console.log = vi.fn(); + console.warn = vi.fn(); mockAxios.reset(); }); afterEach(() => { - (console.log as jest.Mock).mockClear(); - (console.warn as jest.Mock).mockClear(); - jest.clearAllMocks(); + (console.log as Mock).mockClear(); + (console.warn as Mock).mockClear(); + vi.clearAllMocks(); }); const expectNoErrorHandlerMsgLogged = () => { - expect((console.warn as jest.Mock).mock.calls[0][0]).toBe( + expect((console.warn as Mock).mock.calls[0][0]).toBe( `No error handler registered for request ${TEST_ROUTE}.` ); }; @@ -48,27 +48,27 @@ describe("ApiService", () => { it("console logs error on get", async () => { mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(500, mockFailure("some error message")); - await api({ commit: jest.fn(), rootState } as any).get(TEST_ROUTE); + await api({ commit: vi.fn(), rootState } as any).get(TEST_ROUTE); expectNoErrorHandlerMsgLogged(); - expect((console.log as jest.Mock).mock.calls[0][0].errors[0].detail).toBe("some error message"); + expect((console.log as Mock).mock.calls[0][0].errors[0].detail).toBe("some error message"); }); it("console logs error on post", async () => { mockAxios.onPost(`${BASE_URL}${TEST_ROUTE}`, TEST_BODY).reply(500, mockFailure("some error message")); - await api({ commit: jest.fn(), rootState } as any).post(TEST_ROUTE, TEST_BODY); + await api({ commit: vi.fn(), rootState } as any).post(TEST_ROUTE, TEST_BODY); expectNoErrorHandlerMsgLogged(); - expect((console.log as jest.Mock).mock.calls[0][0].errors[0].detail).toBe("some error message"); + expect((console.log as Mock).mock.calls[0][0].errors[0].detail).toBe("some error message"); }); it("commits the the first error message to errors module by default on get", async () => { mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(500, mockFailure("some error message")); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any).get(TEST_ROUTE); @@ -79,7 +79,7 @@ describe("ApiService", () => { it("commits the the first error message to errors module by default on post", async () => { mockAxios.onPost(`${BASE_URL}${TEST_ROUTE}`, TEST_BODY).reply(500, mockFailure("some error message")); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any).post(TEST_ROUTE, TEST_BODY); @@ -95,7 +95,7 @@ describe("ApiService", () => { }; mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(500, failure); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any).get(TEST_ROUTE); @@ -111,7 +111,7 @@ describe("ApiService", () => { }; mockAxios.onPost(`${BASE_URL}${TEST_ROUTE}`, TEST_BODY).reply(500, failure); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any).post(TEST_ROUTE, TEST_BODY); @@ -122,7 +122,7 @@ describe("ApiService", () => { it("commits the first error with the specified type if well formatted on get", async () => { mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(500, mockFailure("some error message")); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any) .withError("TEST_TYPE") @@ -135,7 +135,7 @@ describe("ApiService", () => { it("commits the first error with the specified type if well formatted on post", async () => { mockAxios.onPost(`${BASE_URL}${TEST_ROUTE}`, TEST_BODY).reply(500, mockFailure("some error message")); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any) .withError("TEST_TYPE") @@ -148,7 +148,7 @@ describe("ApiService", () => { it("commits the error type if the error detail is missing on get", async () => { mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(500, mockFailure(null as any)); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any) .withError("TEST_TYPE") .get(TEST_ROUTE); @@ -160,7 +160,7 @@ describe("ApiService", () => { it("commits the error type if the error detail is missing on post", async () => { mockAxios.onPost(`${BASE_URL}${TEST_ROUTE}`, TEST_BODY).reply(500, mockFailure(null as any)); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any) .withError("TEST_TYPE") .post(TEST_ROUTE, TEST_BODY); @@ -172,7 +172,7 @@ describe("ApiService", () => { it("commits the success response with the specified type on get", async () => { mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(200, mockSuccess("test data")); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any) .withSuccess("TEST_TYPE") .get(TEST_ROUTE); @@ -185,7 +185,7 @@ describe("ApiService", () => { it("commits the success response with the specified type on post", async () => { mockAxios.onPost(`${BASE_URL}${TEST_ROUTE}`, TEST_BODY).reply(200, mockSuccess("test data")); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any) .withSuccess("TEST_TYPE") .post(TEST_ROUTE, TEST_BODY); @@ -198,7 +198,7 @@ describe("ApiService", () => { it("commits the success response with the specified type with root true", async () => { mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(200, mockSuccess("test data")); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any) .withSuccess("TEST_TYPE", true) .get(TEST_ROUTE); @@ -211,7 +211,7 @@ describe("ApiService", () => { it("commits the error response with the specified type with root true", async () => { mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(500, mockFailure("TEST ERROR")); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any) .withError("TEST_TYPE", true) .get(TEST_ROUTE); @@ -224,7 +224,7 @@ describe("ApiService", () => { it("handles exception thrown on commit success response by adding expected error", async () => { mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(200, mockSuccess("TEST SUCCESS")); - const commit = jest.fn().mockImplementation((type: string) => { + const commit = vi.fn().mockImplementation((type: string) => { if (type === "TEST_TYPE") { throw new Error("Test Success Mutation Exception"); } @@ -249,7 +249,7 @@ describe("ApiService", () => { it("handles exception thrown on commit error response by adding expected error", async () => { mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(500, mockFailure("TEST FAILURE")); - const commit = jest.fn().mockImplementation((type: string) => { + const commit = vi.fn().mockImplementation((type: string) => { if (type === "TEST_TYPE") { throw new Error("Test Error Mutation Exception"); } @@ -274,7 +274,7 @@ describe("ApiService", () => { it("get returns the response object", async () => { mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(200, mockSuccess("TEST")); - const commit = jest.fn(); + const commit = vi.fn(); const response = await api({ commit, rootState } as any) .withSuccess("TEST_TYPE") .get(TEST_ROUTE); @@ -285,7 +285,7 @@ describe("ApiService", () => { it("post returns the response object", async () => { mockAxios.onPost(`${BASE_URL}${TEST_ROUTE}`, TEST_BODY).reply(200, mockSuccess("TEST")); - const commit = jest.fn(); + const commit = vi.fn(); const response = await api({ commit, rootState } as any) .withSuccess("TEST_TYPE") .post(TEST_ROUTE, TEST_BODY); @@ -295,7 +295,7 @@ describe("ApiService", () => { it("post sets default Content-Type header", async () => { mockAxios.onPost(`${BASE_URL}${TEST_ROUTE}`, TEST_BODY).reply(200, mockSuccess("TEST")); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any) .withSuccess("TEST_TYPE") .post(TEST_ROUTE, TEST_BODY); @@ -305,7 +305,7 @@ describe("ApiService", () => { it("post sets requested Content-Type header", async () => { mockAxios.onPost(`${BASE_URL}${TEST_ROUTE}`, TEST_BODY).reply(200, mockSuccess("TEST")); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any) .withSuccess("TEST_TYPE") .post(TEST_ROUTE, TEST_BODY, "text/plain"); @@ -318,9 +318,9 @@ describe("ApiService", () => { const mockResponse = mockSuccess(fakeData); mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(200, mockResponse); - const spy = jest.spyOn(freezer, "deepFreeze"); + const spy = vi.spyOn(freezer, "deepFreeze"); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any) .freezeResponse() .withSuccess("TEST_TYPE") @@ -336,9 +336,9 @@ describe("ApiService", () => { const fakeData = { name: "d1" }; mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(200, mockSuccess(fakeData)); - const spy = jest.spyOn(freezer, "deepFreeze"); + const spy = vi.spyOn(freezer, "deepFreeze"); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any) .withSuccess("TEST_TYPE") .get(TEST_ROUTE); @@ -350,7 +350,7 @@ describe("ApiService", () => { }); async function expectCouldNotParseAPIResponseError() { - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any).get(TEST_ROUTE); expect(commit.mock.calls.length).toBe(1); @@ -383,33 +383,33 @@ describe("ApiService", () => { it("does nothing on error if ignoreErrors is true", async () => { mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(500, mockFailure("some error message")); - const commit = jest.fn(); + const commit = vi.fn(); await api({ commit, rootState } as any) .withSuccess("whatever") .ignoreErrors() .get("/baseline/"); - expect((console.warn as jest.Mock).mock.calls.length).toBe(0); + expect((console.warn as Mock).mock.calls.length).toBe(0); expect(commit.mock.calls.length).toBe(0); }); it("does not warn that no success handler if ignoring success", async () => { mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(200, mockSuccess(true)); - await api({ commit: jest.fn(), rootState } as any) + await api({ commit: vi.fn(), rootState } as any) .ignoreSuccess() .withError("whatever") .get(TEST_ROUTE); - expect((console.warn as jest.Mock).mock.calls.length).toBe(0); + expect((console.warn as Mock).mock.calls.length).toBe(0); }); it("warns if error and success handlers are not set if not ignoring", async () => { mockAxios.onGet(`${BASE_URL}${TEST_ROUTE}`).reply(200, mockSuccess(true)); - await api({ commit: jest.fn(), rootState } as any).get(TEST_ROUTE); + await api({ commit: vi.fn(), rootState } as any).get(TEST_ROUTE); - const warnings = (console.warn as jest.Mock).mock.calls; + const warnings = (console.warn as Mock).mock.calls; expectNoErrorHandlerMsgLogged(); expect(warnings[1][0]).toBe(`No success handler registered for request ${TEST_ROUTE}.`); diff --git a/app/static/tests/unit/csvUpload.test.ts b/app/static/tests/unit/csvUpload.test.ts index dd69dae36..8a26e171e 100644 --- a/app/static/tests/unit/csvUpload.test.ts +++ b/app/static/tests/unit/csvUpload.test.ts @@ -1,13 +1,12 @@ -import resetAllMocks = jest.resetAllMocks; import { fileTimeout } from "../testUtils"; -import { csvUpload } from "../../src/app/csvUpload"; +import { csvUpload } from "../../src/csvUpload"; describe("CSVUpload", () => { const file = { name: "testFile" } as any; const getMockFileReader = (csvData: string) => { const mockFileReader = {} as any; - const readAsText = jest.fn().mockImplementation(() => { + const readAsText = vi.fn().mockImplementation(() => { mockFileReader.onload({ target: { result: csvData @@ -15,15 +14,15 @@ describe("CSVUpload", () => { }); }); mockFileReader.readAsText = readAsText; - jest.spyOn(global, "FileReader").mockImplementation(() => mockFileReader); + vi.spyOn(global, "FileReader").mockImplementation(() => mockFileReader); return mockFileReader; }; - const postSuccess = jest.fn(); + const postSuccess = vi.fn(); afterEach(() => { - resetAllMocks(); + vi.resetAllMocks(); }); const expectFileRead = (mockFileReader: any) => { @@ -37,10 +36,10 @@ describe("CSVUpload", () => { Error = "Error" } - it("commits data and calls post success on success", (done) => { + it("commits data and calls post success on success", async () => { const mockFileReader = getMockFileReader("a,b\n1,2\n3,4\n5,6\n7,8\n9,10\n"); - const commit = jest.fn(); + const commit = vi.fn(); csvUpload({ commit } as any) .withSuccess(TestMutation.Success) .withError(TestMutation.Error) @@ -48,51 +47,45 @@ describe("CSVUpload", () => { .upload(file); expectFileRead(mockFileReader); - setTimeout(() => { - expect(commit).toHaveBeenCalledTimes(1); - expect(commit.mock.calls[0][0]).toBe(TestMutation.Success); - const expectedSetDataPayload = { - data: [ - { a: 1, b: 2 }, - { a: 3, b: 4 }, - { a: 5, b: 6 }, - { a: 7, b: 8 }, - { a: 9, b: 10 } - ], - columns: ["a", "b"], - timeVariableCandidates: ["a", "b"] - }; - expect(commit.mock.calls[0][1]).toStrictEqual(expectedSetDataPayload); - - expect(postSuccess).toHaveBeenCalledTimes(1); - - done(); - }, fileTimeout); + await new Promise(res => setTimeout(res, fileTimeout)); + expect(commit).toHaveBeenCalledTimes(1); + expect(commit.mock.calls[0][0]).toBe(TestMutation.Success); + const expectedSetDataPayload = { + data: [ + { a: 1, b: 2 }, + { a: 3, b: 4 }, + { a: 5, b: 6 }, + { a: 7, b: 8 }, + { a: 9, b: 10 } + ], + columns: ["a", "b"], + timeVariableCandidates: ["a", "b"] + }; + expect(commit.mock.calls[0][1]).toStrictEqual(expectedSetDataPayload); + + expect(postSuccess).toHaveBeenCalledTimes(1); }); - it("succeeds if post success is not set", (done) => { + it("succeeds if post success is not set", async () => { const mockFileReader = getMockFileReader("a,b\n1,2\n3,4\n5,6\n7,8\n9,10\n"); - const commit = jest.fn(); + const commit = vi.fn(); csvUpload({ commit } as any) .withSuccess(TestMutation.Success) .withError(TestMutation.Error) .upload(file); expectFileRead(mockFileReader); - setTimeout(() => { - expect(commit).toHaveBeenCalledTimes(1); - expect(commit.mock.calls[0][0]).toBe(TestMutation.Success); - expect(postSuccess).not.toHaveBeenCalled(); - - done(); - }, fileTimeout); + await new Promise(res => setTimeout(res, fileTimeout)); + expect(commit).toHaveBeenCalledTimes(1); + expect(commit.mock.calls[0][0]).toBe(TestMutation.Success); + expect(postSuccess).not.toHaveBeenCalled(); }); - it("commits csv parse error", (done) => { + it("commits csv parse error", async () => { const mockFileReader = getMockFileReader("a,b\n1,2,3"); - const commit = jest.fn(); + const commit = vi.fn(); csvUpload({ commit } as any) .withSuccess(TestMutation.Success) .withError(TestMutation.Error) @@ -100,83 +93,75 @@ describe("CSVUpload", () => { .upload(file); expectFileRead(mockFileReader); - setTimeout(() => { - expect(commit).toHaveBeenCalledTimes(1); - expect(commit.mock.calls[0][0]).toBe(TestMutation.Error); - const expectedError = { - error: "An error occurred when loading data", - detail: "Invalid Record Length: columns length is 2, got 3 on line 2" - }; - expect(commit.mock.calls[0][1]).toStrictEqual(expectedError); - expect(postSuccess).not.toHaveBeenCalled(); - done(); - }, fileTimeout); + await new Promise(res => setTimeout(res, fileTimeout)); + expect(commit).toHaveBeenCalledTimes(1); + expect(commit.mock.calls[0][0]).toBe(TestMutation.Error); + const expectedError = { + error: "An error occurred when loading data", + detail: "Invalid Record Length: columns length is 2, got 3 on line 2" + }; + expect(commit.mock.calls[0][1]).toStrictEqual(expectedError); + expect(postSuccess).not.toHaveBeenCalled(); }); - it("commits csv processing error", (done) => { + it("commits csv processing error", async () => { const mockFileReader = getMockFileReader("a,b\n1,2\nhello,4\n5,6\n7,8\n9,10\n"); - const commit = jest.fn(); + const commit = vi.fn(); csvUpload({ commit } as any) .withSuccess(TestMutation.Success) .withError(TestMutation.Error) .then(postSuccess) .upload(file); expectFileRead(mockFileReader); - setTimeout(() => { - expect(commit).toHaveBeenCalledTimes(1); - expect(commit.mock.calls[0][0]).toBe(TestMutation.Error); - const expectedError = { - error: "An error occurred when loading data", - detail: "Data contains non-numeric values: 'hello'" - }; - expect(commit.mock.calls[0][1]).toStrictEqual(expectedError); - expect(postSuccess).not.toHaveBeenCalled(); - done(); - }, fileTimeout); + await new Promise(res => setTimeout(res, fileTimeout)); + expect(commit).toHaveBeenCalledTimes(1); + expect(commit.mock.calls[0][0]).toBe(TestMutation.Error); + const expectedError = { + error: "An error occurred when loading data", + detail: "Data contains non-numeric values: 'hello'" + }; + expect(commit.mock.calls[0][1]).toStrictEqual(expectedError); + expect(postSuccess).not.toHaveBeenCalled(); }); - it("commits file read error", (done) => { + it("commits file read error", async () => { const mockFileReader = {} as any; - const readAsText = jest.fn().mockImplementation(() => { + const readAsText = vi.fn().mockImplementation(() => { mockFileReader.error = { message: "File cannot be read" }; mockFileReader.onerror(); }); mockFileReader.readAsText = readAsText; - jest.spyOn(global, "FileReader").mockImplementation(() => mockFileReader); + vi.spyOn(global, "FileReader").mockImplementation(() => mockFileReader); - const commit = jest.fn(); + const commit = vi.fn(); csvUpload({ commit } as any) .withSuccess(TestMutation.Success) .withError(TestMutation.Error) .then(postSuccess) .upload(file); expectFileRead(mockFileReader); - setTimeout(() => { - expect(commit).toHaveBeenCalledTimes(1); - expect(commit.mock.calls[0][0]).toBe(TestMutation.Error); - const expectedError = { - error: "An error occurred when reading data file", - detail: "File cannot be read" - }; - expect(commit.mock.calls[0][1]).toStrictEqual(expectedError); - expect(postSuccess).not.toHaveBeenCalled(); - done(); - }, fileTimeout); + await new Promise(res => setTimeout(res, fileTimeout)); + expect(commit).toHaveBeenCalledTimes(1); + expect(commit.mock.calls[0][0]).toBe(TestMutation.Error); + const expectedError = { + error: "An error occurred when reading data file", + detail: "File cannot be read" + }; + expect(commit.mock.calls[0][1]).toStrictEqual(expectedError); + expect(postSuccess).not.toHaveBeenCalled(); }); - it("warns when handlers are not registered", (done) => { + it("warns when handlers are not registered", async () => { const mockFileReader = getMockFileReader("a,b\n1,2\n3,4"); - jest.spyOn(global, "FileReader").mockImplementation(() => mockFileReader); - const consoleSpy = jest.spyOn(console, "warn"); - const commit = jest.fn(); + vi.spyOn(global, "FileReader").mockImplementation(() => mockFileReader); + const consoleSpy = vi.spyOn(console, "warn"); + const commit = vi.fn(); csvUpload({ commit } as any).upload(file); expect(consoleSpy).toHaveBeenCalledTimes(2); expect(consoleSpy.mock.calls[0][0]).toBe("No error handler registered for CSVUpload."); expect(consoleSpy.mock.calls[1][0]).toBe("No success handler registered for CSVUpload."); - setTimeout(() => { - expect(commit).not.toHaveBeenCalled(); - done(); - }, fileTimeout); + await new Promise(res => setTimeout(res, fileTimeout)); + expect(commit).not.toHaveBeenCalled(); }); }); diff --git a/app/static/tests/unit/directives/help.test.ts b/app/static/tests/unit/directives/help.test.ts index 818ab6f3d..64b1505d1 100644 --- a/app/static/tests/unit/directives/help.test.ts +++ b/app/static/tests/unit/directives/help.test.ts @@ -1,5 +1,5 @@ -import help from "../../../src/app/directives/help"; -import tooltip from "../../../src/app/directives/tooltip"; +import help from "../../../src/directives/help"; +import tooltip from "../../../src/directives/tooltip"; const binding = { instance: null, @@ -14,7 +14,7 @@ const el = {} as HTMLElement; const expectedHelpString = "Revert to default code - all your changes will be lost"; describe("help directive", () => { it("calls tooltip mounted with help string", () => { - const mockTooltipMounted = jest.spyOn(tooltip, "mounted").mockImplementation(() => {}); + const mockTooltipMounted = vi.spyOn(tooltip, "mounted").mockImplementation(() => {}); help.mounted(el, binding); expect(mockTooltipMounted).toHaveBeenCalledWith(el, { ...binding, @@ -23,7 +23,7 @@ describe("help directive", () => { }); it("calls tooltip beforeUpdate with help string", () => { - const mockTooltipBeforeUpdate = jest.spyOn(tooltip, "beforeUpdate").mockImplementation(() => {}); + const mockTooltipBeforeUpdate = vi.spyOn(tooltip, "beforeUpdate").mockImplementation(() => {}); help.beforeUpdate(el, binding); expect(mockTooltipBeforeUpdate).toHaveBeenCalledWith(el, { ...binding, @@ -32,7 +32,7 @@ describe("help directive", () => { }); it("calls tooltip beforeUnmount", () => { - const mockTooltipBeforeUnmount = jest.spyOn(tooltip, "beforeUnmount").mockImplementation(() => {}); + const mockTooltipBeforeUnmount = vi.spyOn(tooltip, "beforeUnmount").mockImplementation(() => {}); help.beforeUnmount(el); expect(mockTooltipBeforeUnmount).toHaveBeenCalledWith(el); }); diff --git a/app/static/tests/unit/directives/tooltip.test.ts b/app/static/tests/unit/directives/tooltip.test.ts index 1077c6726..83eb9e828 100644 --- a/app/static/tests/unit/directives/tooltip.test.ts +++ b/app/static/tests/unit/directives/tooltip.test.ts @@ -1,7 +1,7 @@ import { ref } from "vue"; import { mount } from "@vue/test-utils"; import { Tooltip } from "bootstrap"; -import tooltip from "../../../src/app/directives/tooltip"; +import tooltip from "../../../src/directives/tooltip"; const expectTooltipConfig = ( el: HTMLElement, @@ -115,7 +115,7 @@ describe("tooltip directive", () => { const tooltipInstance = Tooltip.getInstance(div.element) as any; expect(tooltipInstance._config.title).toBe("hey"); expect(tooltipInstance._config.customClass).toBe("tooltip-success"); - const spyDispose = jest.spyOn(tooltipInstance, "dispose"); + const spyDispose = vi.spyOn(tooltipInstance, "dispose"); await div.trigger("click"); const divClick = wrapper.find("div"); const tooltipClick = Tooltip.getInstance(divClick.element) as any; @@ -152,7 +152,7 @@ describe("tooltip directive", () => { const wrapper = mountTemplate(); const el = wrapper.find("div").element; const tooltipInstance = Tooltip.getInstance(el)!; - const spyDispose = jest.spyOn(tooltipInstance, "dispose"); + const spyDispose = vi.spyOn(tooltipInstance, "dispose"); wrapper.unmount(); expect(spyDispose).toHaveBeenCalled(); }); @@ -161,7 +161,7 @@ describe("tooltip directive", () => { const wrapper = mountTemplate(); const el = wrapper.find("div").element; const tooltipInstance = Tooltip.getInstance(el)!; - const spyDispose = jest.spyOn(tooltipInstance, "dispose"); + const spyDispose = vi.spyOn(tooltipInstance, "dispose"); tooltipInstance.dispose(); wrapper.unmount(); // my dispose above rather than disposing when unmount @@ -184,9 +184,9 @@ describe("tooltip directive", () => { const div = wrapper.find("div"); const el = div.element; const tooltipInstance = Tooltip.getInstance(el)!; - const spyDispose = jest.spyOn(tooltipInstance, "dispose"); - const spyHide = jest.spyOn(tooltipInstance, "hide"); - const spyShow = jest.spyOn(tooltipInstance, "show"); + const spyDispose = vi.spyOn(tooltipInstance, "dispose"); + const spyHide = vi.spyOn(tooltipInstance, "hide"); + const spyShow = vi.spyOn(tooltipInstance, "show"); tooltipInstance.dispose(); await div.trigger("click"); // my dispose above rather than disposing when unmount @@ -209,7 +209,7 @@ describe("tooltip directive", () => { } ); const div = wrapper.find("div"); - const spyHide = jest.spyOn(Tooltip.getInstance(div.element) as any, "hide"); + const spyHide = vi.spyOn(Tooltip.getInstance(div.element) as any, "hide"); expect((Tooltip.getInstance(div.element) as any)._config.title).toBe("hey"); await div.trigger("click"); expect(spyHide).toHaveBeenCalled(); @@ -231,7 +231,7 @@ describe("tooltip directive", () => { } ); const div = wrapper.find("div"); - const spyShow = jest.spyOn(Tooltip.getInstance(div.element) as any, "show"); + const spyShow = vi.spyOn(Tooltip.getInstance(div.element) as any, "show"); expect((Tooltip.getInstance(div.element) as any)._config.title).toBe(""); await div.trigger("click"); expect(spyShow).toHaveBeenCalled(); diff --git a/app/static/tests/unit/excel/mocks.ts b/app/static/tests/unit/excel/mocks.ts index 27b684b50..07d32861a 100644 --- a/app/static/tests/unit/excel/mocks.ts +++ b/app/static/tests/unit/excel/mocks.ts @@ -1,12 +1,12 @@ -export const mockAoaToSheet = jest.fn().mockImplementation((data) => ({ data, type: "aoa" })); -export const mockBookNew = jest.fn().mockImplementation(() => ({ sheets: [] }) as any); -export const mockWriteFile = jest.fn(); -export const mockBookAppendSheet = jest.fn().mockImplementation((workbook: any, worksheet: any, name: string) => { +export const mockAoaToSheet = vi.fn().mockImplementation((data) => ({ data, type: "aoa" })); +export const mockBookNew = vi.fn().mockImplementation(() => ({ sheets: [] }) as any); +export const mockWriteFile = vi.fn(); +export const mockBookAppendSheet = vi.fn().mockImplementation((workbook: any, worksheet: any, name: string) => { (workbook as any).sheets.push({ ...worksheet, name }); }); -const mockJsonToSheet = jest.fn().mockImplementation((data) => ({ data, type: "json" })); +const mockJsonToSheet = vi.fn().mockImplementation((data) => ({ data, type: "json" })); -jest.mock("xlsx", () => ({ +vi.mock("xlsx", () => ({ writeFile: (data: string, fileName: string) => mockWriteFile(data, fileName), utils: { aoa_to_sheet: (data: any) => mockAoaToSheet(data), diff --git a/app/static/tests/unit/excel/wodinModelOutputDownload.test.ts b/app/static/tests/unit/excel/wodinModelOutputDownload.test.ts index df3ddace8..f4dedbbde 100644 --- a/app/static/tests/unit/excel/wodinModelOutputDownload.test.ts +++ b/app/static/tests/unit/excel/wodinModelOutputDownload.test.ts @@ -1,9 +1,9 @@ import { mockBookNew, mockWriteFile } from "./mocks"; import { mockFitDataState, mockFitState, mockBasicState, mockRunState } from "../../mocks"; -import { WodinModelOutputDownload } from "../../../src/app/excel/wodinModelOutputDownload"; -import { ErrorsMutation } from "../../../src/app/store/errors/mutations"; +import { WodinModelOutputDownload } from "../../../src/excel/wodinModelOutputDownload"; +import { ErrorsMutation } from "../../../src/store/errors/mutations"; -const mockSolution = jest.fn().mockImplementation((options) => { +const mockSolution = vi.fn().mockImplementation((options) => { const x = options.mode === "grid" ? [options.tStart, options.tEnd] : options.times; const values = [ { name: "A", y: x.map((xVal: number) => 1 + xVal) }, @@ -26,7 +26,7 @@ describe("WodinModelOutputDownload", () => { }; beforeEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); }); const expectedModelledSheet = { @@ -52,7 +52,7 @@ describe("WodinModelOutputDownload", () => { const rootState = mockBasicState({ run: runState }); - const commit = jest.fn(); + const commit = vi.fn(); const sut = new WodinModelOutputDownload({ rootState, rootGetters, commit } as any, "myFile.xlsx", 101); sut.download(); @@ -86,7 +86,7 @@ describe("WodinModelOutputDownload", () => { }) }); - const commit = jest.fn(); + const commit = vi.fn(); const sut = new WodinModelOutputDownload({ rootState, commit, rootGetters } as any, "myFile.xlsx", 101); sut.download(); @@ -128,7 +128,7 @@ describe("WodinModelOutputDownload", () => { const errorRunState = { ...runState, resultOde: { - solution: jest.fn().mockImplementation(() => { + solution: vi.fn().mockImplementation(() => { throw new Error("test error"); }) } as any @@ -136,7 +136,7 @@ describe("WodinModelOutputDownload", () => { const rootState = mockBasicState({ run: errorRunState }); - const commit = jest.fn(); + const commit = vi.fn(); const sut = new WodinModelOutputDownload({ rootState, commit, rootGetters } as any, "myFile.xlsx", 101); sut.download(); diff --git a/app/static/tests/unit/excel/wodinSensitivitySummaryDownload.test.ts b/app/static/tests/unit/excel/wodinSensitivitySummaryDownload.test.ts index 20a482abe..1f4452604 100644 --- a/app/static/tests/unit/excel/wodinSensitivitySummaryDownload.test.ts +++ b/app/static/tests/unit/excel/wodinSensitivitySummaryDownload.test.ts @@ -1,11 +1,11 @@ import { mockBookNew, mockBookAppendSheet, mockWriteFile } from "./mocks"; import { mockBasicState, mockRunState, mockSensitivityState } from "../../mocks"; -import { WodinSensitivitySummaryDownload } from "../../../src/app/excel/wodinSensitivitySummaryDownload"; +import { WodinSensitivitySummaryDownload } from "../../../src/excel/wodinSensitivitySummaryDownload"; const xValues = [{ beta: 1 }, { beta: 1.1 }, { beta: 1.2 }]; const mockBatch = { successfulVaryingParams: xValues, - valueAtTime: jest.fn().mockImplementation(() => { + valueAtTime: vi.fn().mockImplementation(() => { return { x: xValues, values: [ @@ -14,7 +14,7 @@ const mockBatch = { ] }; }), - extreme: jest.fn().mockImplementation((extremeType: string) => { + extreme: vi.fn().mockImplementation((extremeType: string) => { return { x: xValues, values: [{ name: extremeType, y: [10, 20, 30] }] @@ -31,7 +31,7 @@ const xValuesMulti = [ const mockBatchMulti = { successfulVaryingParams: xValuesMulti, - valueAtTime: jest.fn().mockImplementation(() => { + valueAtTime: vi.fn().mockImplementation(() => { return { x: xValuesMulti, values: [ @@ -40,7 +40,7 @@ const mockBatchMulti = { ] }; }), - extreme: jest.fn().mockImplementation((extremeType: string) => { + extreme: vi.fn().mockImplementation((extremeType: string) => { return { x: xValuesMulti, values: [{ name: extremeType, y: [11, 22, 33, 44] }] @@ -60,7 +60,7 @@ const parameterValues = { describe("WodinSensitivitySummaryDownload", () => { beforeEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); }); it("downloads expected workbook for single varying parameter", () => { @@ -76,7 +76,7 @@ describe("WodinSensitivitySummaryDownload", () => { parameterValues }) }); - const commit = jest.fn(); + const commit = vi.fn(); const context = { rootState, commit } as any; const sut = new WodinSensitivitySummaryDownload(context, "test.xlsx"); sut.download(result); @@ -161,7 +161,7 @@ describe("WodinSensitivitySummaryDownload", () => { parameterValues }) }); - const commit = jest.fn(); + const commit = vi.fn(); const context = { rootState, commit } as any; const sut = new WodinSensitivitySummaryDownload(context, "test.xlsx"); sut.download(result); diff --git a/app/static/tests/unit/localStorageManager.test.ts b/app/static/tests/unit/localStorageManager.test.ts index 8829434fc..2f9f6c468 100644 --- a/app/static/tests/unit/localStorageManager.test.ts +++ b/app/static/tests/unit/localStorageManager.test.ts @@ -1,4 +1,4 @@ -import { localStorageManager } from "../../src/app/localStorageManager"; +import { localStorageManager } from "../../src/localStorageManager"; import { mockUserPreferences } from "../mocks"; describe("localStorageManager for sessions", () => { @@ -6,12 +6,12 @@ describe("localStorageManager for sessions", () => { let spyOnSetItem: any; beforeAll(() => { - spyOnGetItem = jest.spyOn(Storage.prototype, "getItem").mockReturnValue('["session1", "session2"]'); - spyOnSetItem = jest.spyOn(Storage.prototype, "setItem"); + spyOnGetItem = vi.spyOn(Storage.prototype, "getItem").mockReturnValue('["session1", "session2"]'); + spyOnSetItem = vi.spyOn(Storage.prototype, "setItem"); }); beforeEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); }); it("can get session ids", () => { @@ -58,14 +58,14 @@ describe("localStorageManager gets and saves user preferences", () => { let spyOnSetItem: any; beforeAll(() => { - spyOnGetItem = jest + spyOnGetItem = vi .spyOn(Storage.prototype, "getItem") .mockReturnValue('{"showUnlabelledSessions": false, "showDuplicateSessions": true}'); - spyOnSetItem = jest.spyOn(Storage.prototype, "setItem"); + spyOnSetItem = vi.spyOn(Storage.prototype, "setItem"); }); beforeEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); }); it("can get user preferences", () => { @@ -85,11 +85,11 @@ describe("localStorageManager gets default user preferences", () => { let spyOnGetItem: any; beforeAll(() => { - spyOnGetItem = jest.spyOn(Storage.prototype, "getItem").mockReturnValue(null); + spyOnGetItem = vi.spyOn(Storage.prototype, "getItem").mockReturnValue(null); }); beforeEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); }); it("can get default user preferences", () => { diff --git a/app/static/tests/unit/palette.test.ts b/app/static/tests/unit/palette.test.ts index 6e4aab221..d5b0ab30f 100644 --- a/app/static/tests/unit/palette.test.ts +++ b/app/static/tests/unit/palette.test.ts @@ -1,4 +1,4 @@ -import { interpolateColours, paletteData, paletteModel, parseColour, rgb } from "../../src/app/palette"; +import { interpolateColours, paletteData, paletteModel, parseColour, rgb } from "../../src/palette"; describe("parse colours", () => { it("can roundtrip", () => { diff --git a/app/static/tests/unit/plot.test.ts b/app/static/tests/unit/plot.test.ts index 5b73579e9..448084b12 100644 --- a/app/static/tests/unit/plot.test.ts +++ b/app/static/tests/unit/plot.test.ts @@ -5,7 +5,7 @@ import { fitDataToPlotly, paramSetLineStyle, odinToPlotly -} from "../../src/app/plot"; +} from "../../src/plot"; describe("odinToPlotly", () => { const palette = { diff --git a/app/static/tests/unit/router.test.ts b/app/static/tests/unit/router.test.ts index afc5b5060..7bce17f0b 100644 --- a/app/static/tests/unit/router.test.ts +++ b/app/static/tests/unit/router.test.ts @@ -1,17 +1,20 @@ -/* eslint-disable import/first */ const mockWebHistory = {} as any; const mockRouter = {} as any; -jest.mock("vue-router", () => ({ - createWebHistory: jest.fn(), - createRouter: jest.fn() -})); +vi.mock("vue-router", () => { + return { + createWebHistory: vi.fn(), + createRouter: vi.fn(), + RouterLink: null, + RouterView: null + } +}); import { createWebHistory, createRouter } from "vue-router"; -import Mock = jest.Mock; -import { initialiseRouter } from "../../src/app/router"; -import WodinSession from "../../src/app/components/WodinSession.vue"; -import SessionsPage from "../../src/app/components/sessions/SessionsPage.vue"; +import { Mock } from "vitest"; +import { initialiseRouter } from "../../src/router"; +import WodinSession from "../../src/components/WodinSession.vue"; +import SessionsPage from "../../src/components/sessions/SessionsPage.vue"; const mockCreateWebHistory = createWebHistory as Mock; mockCreateWebHistory.mockReturnValue(mockWebHistory); @@ -19,14 +22,14 @@ mockCreateWebHistory.mockReturnValue(mockWebHistory); const mockCreateRouter = createRouter as Mock; mockCreateRouter.mockReturnValue(mockRouter); -const mockPushState = jest.fn(); +const mockPushState = vi.fn(); const realLocation = window.location; const realHistory = window.history; describe("router", () => { beforeEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); }); beforeAll(() => { diff --git a/app/static/tests/unit/serialiser.test.ts b/app/static/tests/unit/serialiser.test.ts index 0a8d255b6..235070ba5 100644 --- a/app/static/tests/unit/serialiser.test.ts +++ b/app/static/tests/unit/serialiser.test.ts @@ -1,13 +1,13 @@ -import { BasicState } from "../../src/app/store/basic/state"; -import { AppType, VisualisationTab } from "../../src/app/store/appState/state"; +import { BasicState } from "../../src/store/basic/state"; +import { AppType, VisualisationTab } from "../../src/store/appState/state"; import { SensitivityPlotExtreme, SensitivityPlotType, SensitivityScaleType, SensitivityVariationType -} from "../../src/app/store/sensitivity/state"; -import { deserialiseState, serialiseState } from "../../src/app/serialise"; -import { FitState } from "../../src/app/store/fit/state"; +} from "../../src/store/sensitivity/state"; +import { deserialiseState, serialiseState } from "../../src/serialise"; +import { FitState } from "../../src/store/fit/state"; import { mockCodeState, mockFitDataState, @@ -20,16 +20,16 @@ import { mockSessionsState, mockVersionsState } from "../mocks"; -import { defaultState as defaultGraphsState } from "../../src/app/store/graphs/graphs"; -import { Language } from "../../src/app/types/languageTypes"; -import { AdvancedOptions } from "../../src/app/types/responseTypes"; -import { AdvancedComponentType } from "../../src/app/store/run/state"; -import { noSensitivityUpdateRequired } from "../../src/app/store/sensitivity/sensitivity"; -import { defaultGraphSettings } from "../../src/app/store/graphs/state"; - -jest.mock("../../src/app/utils", () => { +import { defaultState as defaultGraphsState } from "../../src/store/graphs/graphs"; +import { Language } from "../../src/types/languageTypes"; +import { AdvancedOptions } from "../../src/types/responseTypes"; +import { AdvancedComponentType } from "../../src/store/run/state"; +import { noSensitivityUpdateRequired } from "../../src/store/sensitivity/sensitivity"; +import { defaultGraphSettings } from "../../src/store/graphs/state"; + +vi.mock("../../src/utils", () => { return { - newUid: jest.fn().mockReturnValue("12345") + newUid: vi.fn().mockReturnValue("12345") }; }); @@ -42,16 +42,16 @@ describe("serialise", () => { const modelState = { compileRequired: true, odinRunnerOde: { - wodinRun: jest.fn(), - wodinFit: jest.fn(), - wodinFitValue: jest.fn(), - batchParsRange: jest.fn(), - batchParsDisplace: jest.fn(), - batchRun: jest.fn() + wodinRun: vi.fn(), + wodinFit: vi.fn(), + wodinFitValue: vi.fn(), + batchParsRange: vi.fn(), + batchParsDisplace: vi.fn(), + batchRun: vi.fn() }, odinRunnerDiscrete: { - wodinRunDiscrete: jest.fn(), - batchRunDiscrete: jest.fn() + wodinRunDiscrete: vi.fn(), + batchRunDiscrete: vi.fn() }, odinModelResponse: { valid: true, @@ -81,7 +81,7 @@ describe("serialise", () => { model: "a test model", error: { line: [1], message: "test model error" } }, - odin: jest.fn(), + odin: vi.fn(), paletteModel: { S: "#f00", I: "#0f0", R: "#00f" }, odinModelCodeError: { error: "odin error", detail: "test odin error" } }; @@ -102,7 +102,7 @@ describe("serialise", () => { parameterValues: { alpha: 0, beta: 2.2 }, endTime: 10 }, - solution: jest.fn(), + solution: vi.fn(), error: { error: "run error", detail: "run error detail" } }, resultDiscrete: { @@ -111,7 +111,7 @@ describe("serialise", () => { endTime: 5, numberOfReplicates: 6 }, - solution: jest.fn(), + solution: vi.fn(), error: { error: "run discrete error", detail: "run discrete error detail" } }, parameterSetsCreated: 3, @@ -130,7 +130,7 @@ describe("serialise", () => { parameterValues: { alpha: 1, beta: 3.3 }, endTime: 10 }, - solution: jest.fn(), + solution: vi.fn(), error: { error: "param set run error", detail: "param set run error detail" } } }, @@ -208,12 +208,12 @@ describe("serialise", () => { }, batch: { pars: sensitivityBatchPars, - solutions: [jest.fn(), jest.fn()], + solutions: [vi.fn(), vi.fn()], errors: [], successfulVaryingParams: [], - valueAtTime: jest.fn(), - extreme: jest.fn(), - compute: jest.fn() + valueAtTime: vi.fn(), + extreme: vi.fn(), + compute: vi.fn() }, error: { error: "sensitivity error", detail: "sensitivity error detail" } }, @@ -225,12 +225,12 @@ describe("serialise", () => { }, batch: { pars: sensitivityParamSetBatchPars, - solutions: [jest.fn(), jest.fn()], + solutions: [vi.fn(), vi.fn()], errors: [], successfulVaryingParams: [], - valueAtTime: jest.fn(), - extreme: jest.fn(), - compute: jest.fn() + valueAtTime: vi.fn(), + extreme: vi.fn(), + compute: vi.fn() }, error: { error: "param set sensitivity error", detail: "param set sensitivity error detail" } } @@ -293,12 +293,12 @@ describe("serialise", () => { }, batch: { pars: multiSensitivityBatchPars, - solutions: [jest.fn(), jest.fn()], + solutions: [vi.fn(), vi.fn()], errors: [], successfulVaryingParams: [], - valueAtTime: jest.fn(), - extreme: jest.fn(), - compute: jest.fn() + valueAtTime: vi.fn(), + extreme: vi.fn(), + compute: vi.fn() }, error: { error: "multiSensitivity error", detail: "multiSensitivity error detail" } } @@ -350,7 +350,7 @@ describe("serialise", () => { ], link: { time: "t", data: "cases", model: "R" } }, - solution: jest.fn(), + solution: vi.fn(), error: { error: "fit error", detail: "fit error detail" } } }; diff --git a/app/static/tests/unit/utils.test.ts b/app/static/tests/unit/utils.test.ts index e261a27a2..156cc3d06 100644 --- a/app/static/tests/unit/utils.test.ts +++ b/app/static/tests/unit/utils.test.ts @@ -6,8 +6,8 @@ import { processFitData, newUid, joinStringsSentence -} from "../../src/app/utils"; -import { SensitivityScaleType, SensitivityVariationType } from "../../src/app/store/sensitivity/state"; +} from "../../src/utils"; +import { SensitivityScaleType, SensitivityVariationType } from "../../src/store/sensitivity/state"; import { mockBatchParsDisplace, mockBatchParsRange } from "../mocks"; describe("freezer", () => { @@ -318,11 +318,11 @@ describe("generateBatchPars", () => { } } as any; - const spyBatchParsRange = jest.spyOn(rootState.model.odinRunnerOde, "batchParsRange"); - const spyBatchParsDisplace = jest.spyOn(rootState.model.odinRunnerOde, "batchParsDisplace"); + const spyBatchParsRange = vi.spyOn(rootState.model.odinRunnerOde, "batchParsRange"); + const spyBatchParsDisplace = vi.spyOn(rootState.model.odinRunnerOde, "batchParsDisplace"); afterEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); }); const percentSettings = {