chore: migrate a bunch of tests to vitest (#21514)

This commit is contained in:
ケイラ
2026-01-15 12:38:29 -07:00
committed by GitHub
parent d25d95231f
commit d2d7c0ee40
25 changed files with 86 additions and 89 deletions
@@ -22,13 +22,12 @@ import {
} from "./ProxyContext";
import type * as ProxyLatency from "./useProxyLatency";
// Mock useProxyLatency to use a hard-coded latency. 'jest.mock' must be called
// here and not inside a unit test.
jest.mock("contexts/useProxyLatency", () => ({
// Mock useProxyLatency to use a hard-coded latency.
vi.mock("contexts/useProxyLatency", () => ({
useProxyLatency: () => {
return {
proxyLatencies: hardCodedLatencies,
refetch: jest.fn(),
refetch: vi.fn(),
loaded: true,
};
},
@@ -48,9 +48,9 @@ const createAuthWrapper = (override: Partial<AuthContextValue>) => {
organizationIds: undefined,
signInError: undefined,
updateProfileError: undefined,
signOut: jest.fn(),
signIn: jest.fn(),
updateProfile: jest.fn(),
signOut: vi.fn(),
signIn: vi.fn(),
updateProfile: vi.fn(),
...override,
};
const Wrapper: FC<PropsWithChildren> = ({ children }) => {
@@ -66,7 +66,7 @@ const createAuthWrapper = (override: Partial<AuthContextValue>) => {
describe("useAuthenticated", () => {
it("throws an error if it is used outside of a context with user", () => {
jest.spyOn(console, "error").mockImplementation(() => {});
vi.spyOn(console, "error").mockImplementation(() => {});
expect(() => {
renderHook(() => useAuthenticated(), {
@@ -74,11 +74,11 @@ describe("useAuthenticated", () => {
});
}).toThrow("User is not authenticated.");
jest.restoreAllMocks();
vi.restoreAllMocks();
});
it("throws an error if it is used outside of a context with permissions", () => {
jest.spyOn(console, "error").mockImplementation(() => {});
vi.spyOn(console, "error").mockImplementation(() => {});
expect(() => {
renderHook(() => useAuthenticated(), {
@@ -86,7 +86,7 @@ describe("useAuthenticated", () => {
});
}).toThrow("Permissions are not available.");
jest.restoreAllMocks();
vi.restoreAllMocks();
});
it("returns auth context values for authenticated context", () => {