Skip to content

Commit

Permalink
Replace jest with vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderson1993 committed Nov 20, 2023
1 parent 41abae1 commit d5de106
Show file tree
Hide file tree
Showing 19 changed files with 1,953 additions and 1,507 deletions.
6 changes: 3 additions & 3 deletions client/react-test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import {
import {MockNetRequestContext} from "@thorium/live-query/client/mockContext";
import {AppRouter} from "@server/init/router";
import {inferRouterOutputs} from "@thorium/live-query/server/types";

import {vi} from "vitest";
// @ts-expect-error
global.IS_REACT_ACT_ENVIRONMENT = true;

let netSendResponse: {response: any} = {response: ""};
const netSendSpy = jest.fn((input, params) => netSendResponse);
const netSendSpy = vi.fn((input, params) => netSendResponse);
function setNetSendResponse(response: any) {
netSendResponse = {response};
}
global.fetch = jest.fn((url: URL, {body}: {body: FormData}) => {
global.fetch = vi.fn((url: URL, {body}: {body: FormData}) => {
if (url.pathname.toLowerCase() === "/netsend") {
let bodyObj: any = {};

Expand Down
9 changes: 5 additions & 4 deletions client/src/cards/OfficersLog/OfficersLog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import OfficersLog from ".";
import {render} from "client/react-test-utils";
import userEvent from "@testing-library/user-event";
import {QueryClient, QueryClientProvider} from "@tanstack/react-query";

test("it should render without error", async () => {
const queryClient = new QueryClient();

Expand All @@ -23,12 +24,12 @@ test("it should render without error", async () => {
},
}
);
const logEl = await findByText("@560.60");
expect(logEl).toBeInTheDocument();
const logEl = await findByText("@560.60", {}, {timeout: 5000});
expect(logEl).toBeDefined();
userEvent.click(logEl);
expect(await findByText("This is a test log entry")).toBeInTheDocument();
expect(await findByText("This is a test log entry")).toBeDefined();
await userEvent.click(await findByText("Clear"));
expect(queryByText("This is a test log entry")).not.toBeInTheDocument();
expect(queryByText("This is a test log entry")).toBeNull();
await userEvent.click(await findByText("New Log Entry"));
const entryText = "This is a new log entry.";
await userEvent.type(await findByRole("textbox"), entryText);
Expand Down
6 changes: 4 additions & 2 deletions client/src/pages/Config/Starmap/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import SystemMarker from "@client/components/Starmap/SystemMarker";
import {q} from "@client/context/AppContext";
import {LiveQueryContext} from "@thorium/live-query/client/liveQueryContext";
import {MockNetRequestContext} from "@thorium/live-query/client/mockContext";
jest.mock("scheduler", () => require("scheduler/unstable_mock"));
import {vi} from "vitest";

vi.mock("scheduler", () => require("scheduler/unstable_mock"));

//@ts-expect-error Mocking globals
globalThis.DOMRect = class {
fromRect = jest.fn();
fromRect = vi.fn();
};
//@ts-expect-error Act environment
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
Expand Down
Loading

0 comments on commit d5de106

Please sign in to comment.