passing react tests

This commit is contained in:
Drew Taylor
2021-07-21 17:15:34 -07:00
parent 1bb679a3f8
commit e09ce9bd41
16 changed files with 747 additions and 332 deletions

View File

@@ -4,7 +4,7 @@ jest.mock("../Contexts/UpdatesContext");
jest.mock("../Contexts/UserContext");
jest.mock("../../services/monitoring");
import { render, screen, cleanup, waitForElementToBeRemoved } from "@testing-library/react";
import { render, screen, cleanup, waitFor, waitForElementToBeRemoved } from "@testing-library/react";
import { setToken } from "../Contexts/UserContext";
import { TEST_AUTH_OBJECT } from "../../utils/testing"
import App from ".";
@@ -26,6 +26,13 @@ const check = async (path, selector, compare) => {
expect(container).toMatchSnapshot();
};
const sleepAndCheck = async (path, selector, compare) => {
const container = await renderRoute(path);
await waitFor(() => { });
expect(container.querySelector(selector).innerHTML).toEqual(compare);
expect(container).toMatchSnapshot();
};
describe("App", () => {
beforeAll(() => {
// Stablize Table Pagination control ids
@@ -93,12 +100,12 @@ describe("App", () => {
it("Route / authenticated", async () => {
setToken(TEST_AUTH_OBJECT);
await check("/", "h1", "Welcome John!");
await sleepAndCheck("/", "h1", "Welcome John!");
});
it("Route /home authenticated", async () => {
setToken(TEST_AUTH_OBJECT);
await check("/home", "h1", "Welcome John!");
await sleepAndCheck("/home", "h1", "Welcome John!");
});
it("Route /package-upload authenticated", async () => {