-
Notifications
You must be signed in to change notification settings - Fork 29
/
App.test.js
35 lines (30 loc) · 1.17 KB
/
App.test.js
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
29
30
31
32
33
34
35
import React from "react";
import { render, screen, userEvent, fireEvent } from "../test-utils";
import App from "../App";
describe("The App component", () => {
it("renders the app skeleton", async () => {
const { container } = await render(<App />);
expect(container.firstChild).toMatchSnapshot();
});
it("renders a green dot when successfully connected", async () => {
await render(<App />);
expect(screen.getByTitle("connected")).toBeInTheDocument();
});
it("renders a red dot when not connected", async () => {
const { ws } = await render(<App />);
ws.close();
expect(screen.getByTitle("disconnected")).toBeInTheDocument();
});
it("sends the message when submitting the form", async () => {
const { ws } = await render(<App />);
const input = screen.getByPlaceholderText("type your message here...");
userEvent.type(input, "Hello there");
fireEvent.submit(input);
expect(screen.getByText("(sent) Hello there")).toBeInTheDocument();
await expect(ws).toReceiveMessage("Hello there");
ws.send("[echo] Hello there");
expect(
screen.getByText("(received) [echo] Hello there")
).toBeInTheDocument();
});
});