moonfire-nvr/ui/src/App.test.tsx
Scott Lamb e9a25322b5 upgrade msw 1->2, fix network error case
In the upgrade I managed to dust off some tests that I'd been skipping
for quite a while. It turns out one of them was pointing out a real
problem: in the network error case, we didn't display the error to the
user properly. It's really sad this reaches our code as a `TypeError`,
but it is what it is.
2023-12-18 17:08:19 -08:00

25 lines
901 B
TypeScript

// This file is part of Moonfire NVR, a security camera network video recorder.
// Copyright (C) 2021 The Moonfire NVR Authors; see AUTHORS and LICENSE.txt.
// SPDX-License-Identifier: GPL-v3.0-or-later WITH GPL-3.0-linking-exception
import { screen } from "@testing-library/react";
import App from "./App";
import { renderWithCtx } from "./testutil";
import { http, HttpResponse } from "msw";
import { setupServer } from "msw/node";
import { beforeAll, afterAll, afterEach, expect, test } from "vitest";
const server = setupServer(
http.get("/api/", () => {
return HttpResponse.text("server error", { status: 503 });
})
);
beforeAll(() => server.listen({ onUnhandledRequest: "error" }));
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
test("instantiate", async () => {
renderWithCtx(<App />);
expect(screen.getByText(/Moonfire NVR/)).toBeInTheDocument();
});