26 lines
791 B
TypeScript
26 lines
791 B
TypeScript
import { describe, it, expect, beforeEach } from "vitest";
|
|
import { render, screen } from "@testing-library/react";
|
|
import { MemoryRouter } from "react-router-dom";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import App from "./App";
|
|
import { useAuth } from "@/store/auth";
|
|
|
|
function renderAt(path: string) {
|
|
const qc = new QueryClient();
|
|
return render(
|
|
<QueryClientProvider client={qc}>
|
|
<MemoryRouter initialEntries={[path]}>
|
|
<App />
|
|
</MemoryRouter>
|
|
</QueryClientProvider>
|
|
);
|
|
}
|
|
|
|
describe("routing guard", () => {
|
|
beforeEach(() => useAuth.getState().clear());
|
|
it("redirects to login when no token", () => {
|
|
renderAt("/");
|
|
expect(screen.getByText(/Вход в приложение/i)).toBeInTheDocument();
|
|
});
|
|
});
|