forked from nitin42/animate-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhoc.test.js
85 lines (69 loc) · 1.88 KB
/
hoc.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React from "react";
import renderer from "react-test-renderer";
import { keyframes } from "styled-components";
import "jest-styled-components";
import { shallow } from "enzyme";
import HOC from "../src/containers/HOC";
const sample = keyframes`
0% {
opacity: 0;
}
100% {
opacity: 1;
}
`;
const Sample = HOC("Sample", sample);
const sampleComponent = (
<Sample duration="2s">
Hello World!
</Sample>
);
let App = () => {
return (
<div>
<p>Sign of Times</p>
</div>
);
};
describe('High Order Component', () => {
it("should be a function", () => {
expect(typeof HOC).toBe("function");
});
it("wraps the children under h1 element", () => {
const tree = renderer
.create(
<Sample duration="2s" as="h1">
Hello World!
</Sample>
)
.toJSON();
expect(tree).toMatchSnapshot();
});
it("renders the Component passed through component prop", () => {
const tree = renderer.create(
<Sample duration="2s" as="h1" component={App} />
).toJSON();
expect(tree).toMatchSnapshot();
})
it("wraps the children under div (default)", () => {
const tree = renderer.create(sampleComponent).toJSON();
expect(tree).toMatchSnapshot();
});
it("matches the keyframes created by styled-components and default props", () => {
const tree = renderer.create(sampleComponent).toJSON();
expect(tree).toMatchStyledComponentsSnapshot();
});
it("calls componentDidMount lifecycle method", () => {
const wrapper = shallow(sampleComponent);
wrapper.instance().componentDidMount();
// Also calls store() method when component mounts.
});
it("updates the styles when the component mounts", () => {
const wrapper = shallow(sampleComponent);
wrapper.instance().componentDidMount();
expect(wrapper.state("styles")).toEqual({
animation: "UNeSH 2s ease 0s 1 normal none running",
backfaceVisibility: "visible"
});
});
})