-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathHeading.test.tsx
38 lines (28 loc) · 866 Bytes
/
Heading.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
import { render } from "@testing-library/react";
import { mockReactRedux } from "mock-react-redux";
import * as React from "react";
import { useSelector } from "react-redux";
type RootState = {
title: string;
};
const selectTitle = (state: RootState) => state.title;
const Heading = () => {
const title = useSelector(selectTitle);
return <h1>{title}</h1>;
};
describe(Heading, () => {
describe("Mocking State", () => {
it("renders the title from state", () => {
mockReactRedux().state({ title: "Test Title" });
const view = render(<Heading />);
view.getByText("Test Title");
});
});
describe("Mocking Selectors", () => {
it("renders the title from state", () => {
mockReactRedux().give(selectTitle, "Test Title");
const view = render(<Heading />);
view.getByText("Test Title");
});
});
});