-
Notifications
You must be signed in to change notification settings - Fork 137
/
example.test.tsx
46 lines (35 loc) · 1.39 KB
/
example.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
37
38
39
40
41
42
43
44
45
46
import { it, expect } from "@jest/globals";
import { render } from "@testing-library/react";
import events from "@testing-library/user-event";
import { BrowserRouter } from "react-router-dom";
import { MemoryRouter } from "react-router";
import { Provider } from "react-redux";
import { initStore } from "./store";
import { Application } from "./Application";
it('по адресу /about должна открываться страница "о проекте"', () => {
const store = initStore();
const application = (
<MemoryRouter initialEntries={["/about"]} initialIndex={0}>
<Provider store={store}>
<Application />
</Provider>
</MemoryRouter>
);
const { getByTestId } = render(application);
expect(getByTestId("page-title").textContent).toEqual("About");
});
it("если добавить элемент, он появляется в списке", async () => {
const store = initStore();
const application = (
<BrowserRouter>
<Provider store={store}>
<Application />
</Provider>
</BrowserRouter>
);
const { getByTestId, getAllByTestId } = render(application);
await events.type(getByTestId("input-add"), "Сделать домашку");
await events.click(getByTestId("button-add"));
const items = getAllByTestId("list-item");
expect(items.map((el) => el.textContent)).toContain("Сделать домашку");
});