Files
ThreadNet-Web/apps/web/test/setup/adapter.ts
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.6 KiB
TypeScript
Raw Normal View History

2026-06-19 16:34:18 +01:00
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
2026-07-30 10:11:29 +01:00
import { vi } from "vitest";
import * as vitest from "vitest";
2026-06-19 16:34:18 +01:00
import { mocked as jestMocked } from "jest-mock";
2026-07-03 11:10:04 +01:00
export const isJest = typeof jest !== "undefined";
2026-06-19 16:34:18 +01:00
/**
* Subset of the vitest API surface, with jest equivalents for the same functions when running under jest.
*/
const adapter = {
fn: isJest ? (jest.fn as unknown as typeof vi.fn) : vi.fn,
spyOn: isJest ? (jest.spyOn as unknown as typeof vi.spyOn) : vi.spyOn,
mocked: isJest ? (jestMocked as typeof vi.mocked) : vi.mocked,
2026-07-07 10:40:22 +01:00
advanceTimersByTime: isJest
? (jest.advanceTimersByTime as unknown as typeof vi.advanceTimersByTime)
: vi.advanceTimersByTime,
} as Pick<typeof vi, "fn" | "spyOn" | "mocked" | "advanceTimersByTime">;
2026-06-19 16:34:18 +01:00
const mocked = adapter.mocked;
export { adapter as vi, mocked };
2026-07-30 10:11:29 +01:00
const _expect = isJest ? (expect as unknown as typeof vitest.expect) : vitest.expect;
const _beforeAll = isJest ? (beforeAll as unknown as typeof vitest.beforeAll) : vitest.beforeAll;
const _afterAll = isJest ? (afterAll as unknown as typeof vitest.afterAll) : vitest.afterAll;
const _beforeEach = isJest ? (beforeEach as unknown as typeof vitest.beforeEach) : vitest.beforeEach;
const _afterEach = isJest ? (afterEach as unknown as typeof vitest.afterEach) : vitest.afterEach;
export {
_expect as expect,
_beforeAll as beforeAll,
_afterAll as afterAll,
_beforeEach as beforeEach,
_afterEach as afterEach,
};
2026-07-06 15:10:50 +01:00
2026-06-19 16:34:18 +01:00
export { type Mocked, type MockedObject } from "vitest";