mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: migrate a bunch of tests to vitest (#21514)
This commit is contained in:
@@ -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,
|
||||
};
|
||||
},
|
||||
+7
-7
@@ -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", () => {
|
||||
Reference in New Issue
Block a user