-
Notifications
You must be signed in to change notification settings - Fork 8
/
AddButton.test.js
65 lines (52 loc) · 1.64 KB
/
AddButton.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React from "react";
import { AddButton } from "./AddButton";
import { shallow, configure } from "enzyme";
import * as Adapter from "enzyme-adapter-react-16";
configure({ adapter: new Adapter.default() });
describe("AddButton", () => {
const addCustomSinMock = jest.fn();
const wrapper = shallow(
<AddButton addCustomSin={addCustomSinMock} t={(key) => key} />
);
const instance = wrapper.instance();
describe("constructor", () => {
const state = instance.state;
it("should be defined", () => {
expect(wrapper.exists()).toBeTruthy();
});
it("should have showModal as false by default", () => {
expect(state.showModal).toBe(false);
});
it("should have inputValue of empty string by default", () => {
expect(state.inputValue).toEqual("");
});
});
describe("handleShow", () => {
it("should set showModal to true", () => {
instance.handleShow();
expect(instance.state.showModal).toBe(true);
});
});
describe("handleClose", () => {
it("should set showModal to false", () => {
instance.state.showModal = true;
instance.handleClose();
expect(instance.state.showModal).toBe(false);
});
});
describe("handleAdd", () => {
beforeEach(() => {
jest.spyOn(instance, "handleClose");
instance.handleAdd();
});
it("should call addCustomSin", () => {
expect(addCustomSinMock).toHaveBeenCalled();
});
it("should set inputValue to empty string", () => {
expect(instance.state.inputValue).toEqual("");
});
it("should call handleClose", () => {
expect(instance.handleClose).toHaveBeenCalled();
});
});
});