-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWithState.test.tsx
36 lines (31 loc) · 954 Bytes
/
WithState.test.tsx
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
36
import React from "react";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import "@testing-library/jest-dom";
import { WithState } from "./WithState";
describe("WithState", () => {
it("Renders without crashing", async () => {
render(
<WithState initialState={0}>
{({ state: counter, setState: setCounter }) => {
return (
<>
<div>Counter: {counter}</div>
<button
data-testid="button"
onClick={() => setCounter(counter + 1)}
>
Increment
</button>
</>
);
}}
</WithState>,
);
const button = screen.getByTestId("button");
await userEvent.click(button);
await userEvent.click(button);
await userEvent.click(button);
expect(screen.getByText("Counter: 3")).toBeInTheDocument();
});
});