This repository has been archived by the owner on Jun 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
59 lines (49 loc) · 1.48 KB
/
index.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
import React from "react";
import { render, fireEvent } from "react-testing-library";
import useInstance from ".";
const Test = props => {
const [instance, update] = useInstance(props.initialInstanceState);
const onClick = () => update((instance.test = "updated"));
return <button onClick={onClick}>{instance.test}</button>;
};
test("instance is initialized with literal value", () => {
// Given
const initialInstanceState = {
test: "Initial instance state"
};
// When
const container = render(
<Test initialInstanceState={initialInstanceState} />
);
// Then
const button = container.getByText("Initial instance state");
expect(button).not.toBeUndefined();
});
test("instance is initialized with function that returns a literal value", () => {
// Given
const initialInstanceState = {
test: "Initial instance state"
};
// When
const container = render(
<Test initialInstanceState={() => initialInstanceState} />
);
// Then
const button = container.getByText("Initial instance state");
expect(button).not.toBeUndefined();
});
test("component is updated when update is called", () => {
// Given
const initialInstanceState = {
test: "Initial instance state"
};
const container = render(
<Test initialInstanceState={initialInstanceState} />
);
// When
let button = container.getByText("Initial instance state");
fireEvent.click(button);
// Then
button = container.getByText("updated");
expect(button).not.toBeUndefined();
});