mirror of
https://github.com/coder/coder.git
synced 2026-10-24 01:26:25 +08:00
34 lines
1000 B
TypeScript
34 lines
1000 B
TypeScript
import { createTestQueryClient } from "testHelpers/renderHelpers";
|
|
import { renderHook } from "@testing-library/react";
|
|
import type { FC, PropsWithChildren } from "react";
|
|
import { QueryClientProvider } from "react-query";
|
|
import { AuthProvider, useAuthContext } from "./AuthProvider";
|
|
|
|
const Wrapper: FC<PropsWithChildren> = ({ children }) => {
|
|
return (
|
|
<QueryClientProvider client={createTestQueryClient()}>
|
|
<AuthProvider>{children}</AuthProvider>
|
|
</QueryClientProvider>
|
|
);
|
|
};
|
|
|
|
describe("useAuth", () => {
|
|
it("throws an error if it is used outside of <AuthProvider />", () => {
|
|
jest.spyOn(console, "error").mockImplementation(() => {});
|
|
|
|
expect(() => {
|
|
renderHook(() => useAuthContext());
|
|
}).toThrow("useAuth should be used inside of <AuthProvider />");
|
|
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
it("returns AuthContextValue when used inside of <AuthProvider />", () => {
|
|
expect(() => {
|
|
renderHook(() => useAuthContext(), {
|
|
wrapper: Wrapper,
|
|
});
|
|
}).not.toThrow();
|
|
});
|
|
});
|