This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate-style-snapshots.js
79 lines (65 loc) · 1.65 KB
/
generate-style-snapshots.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
const React = require("react");
const { StyleSheet, Text } = require("react-native");
const TestRenderer = require("react-test-renderer");
const {
addSerializers,
compose,
hoistStyleTransform,
justChildren,
replaceTransform,
stylePrinter
} = require("@times-components/jest-serializer");
const styled = require("styled-components").default;
const Enzyme = require("enzyme");
const mount = require("enzyme").mount;
const Adapter = require("enzyme-adapter-react-16");
Enzyme.configure({ adapter: new Adapter() });
addSerializers(
expect,
compose(
stylePrinter,
replaceTransform({
div: justChildren,
Foo: justChildren
}),
hoistStyleTransform
)
);
require("jest-styled-components");
it("1. snapshot for style block", () => {
const styles = StyleSheet.create({
test: {
color: "blue"
}
});
const testInstance = TestRenderer.create(
<Text foo="bar" style={styles.test}>
Some text
</Text>
);
expect(testInstance).toMatchSnapshot();
});
it("2. snapshot for style block with array", () => {
const StyledH1 = styled.h1`
font-size: 1.5em;
text-align: center;
color: palevioletred;
`;
const Foo = () => <div>{[<StyledH1 key="1" />, <StyledH1 key="2" />]}</div>;
const wrapper = mount(<Foo />);
expect(wrapper).toMatchSnapshot();
});
it("3. snapshot for style block and styled components", () => {
const styles = StyleSheet.create({
test: {
color: "blue"
}
});
const StyledH1 = styled.h1`
font-size: 1.5em;
text-align: center;
color: palevioletred;
`;
const wrapper = mount(<StyledH1 style={styles.test} />);
expect(wrapper).toMatchSnapshot();
});