-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.test.js
More file actions
28 lines (25 loc) · 865 Bytes
/
App.test.js
File metadata and controls
28 lines (25 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
import App from "./App";
beforeEach(() => {
window.fetch = jest.fn().mockImplementation(() =>
Promise.resolve({
json: () => Promise.resolve(true),
})
);
});
test("should render form correctly", () => {
render(<App />);
const label = screen.getByText("Enter GH API key:");
expect(label).toBeInTheDocument();
});
test("should render error message when repos could not be fetched", async () => {
render(<App />);
const input = document.querySelector("input");
fireEvent.change(input, { target: { value: "ghb_mock" } });
fireEvent.click(document.querySelector("button"));
//should render error as fetche is not mocked
await waitFor(() => {
const error = screen.queryByText("Enter a valid API key.");
expect(error).toBeInTheDocument();
});
});