-
Notifications
You must be signed in to change notification settings - Fork 1
/
hooks.enzyme.test.js
33 lines (26 loc) · 1.07 KB
/
hooks.enzyme.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
import React from "react";
import { mount } from "enzyme";
import HooksFoo from "../../components/hooks";
describe("These test suite(s) is/are designed to demonstrate how components with basic hooks can be tested", () => {
let hooksFooWrapper;
let consoleLogSpy;
beforeEach(() => {
consoleLogSpy = jest.spyOn(console, "log").mockImplementation();
// Enzyme's shallow renderer does not trigger useEffect.
hooksFooWrapper = mount(<HooksFoo />);
});
afterEach(() => {
consoleLogSpy.mockRestore();
});
describe("when the component mounts for the first time", () => {
it("logs the message to the console with 0", () => {
expect(consoleLogSpy).toHaveBeenCalledWith(`Count has changed to 0.`);
});
});
describe("when `count` changes", () => {
it("logs the message to the console with the increased value", () => {
hooksFooWrapper.find("button").simulate("click");
expect(consoleLogSpy).toHaveBeenCalledWith(`Count has changed to 1.`);
});
});
});