Skip to content

Commit a124080

Browse files
committed
add snapshot test for Parallax component
1 parent c157030 commit a124080

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

__tests__/Parallax.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3+
import renderer from 'react-test-renderer';
34
import Parallax from 'components/Parallax';
45
import ParallaxProvider from 'components/ParallaxProvider';
56
import ParallaxController from 'libs/ParallaxController';
@@ -12,6 +13,46 @@ describe('Expect the <Parallax> component', () => {
1213
global.ParallaxController = undefined;
1314
});
1415

16+
it('to render correctly', () => {
17+
// Workaround for refs
18+
// See https://github.com/facebook/react/issues/7740
19+
const div = document.createElement('div');
20+
function createNodeMock() {
21+
return {
22+
getBoundingClientRect: () => div.getBoundingClientRect(),
23+
};
24+
}
25+
26+
const tree = renderer
27+
.create(
28+
<ParallaxProvider>
29+
<Parallax
30+
className="class-foo"
31+
disabled={false}
32+
offsetXMax={100}
33+
offsetXMin={-100}
34+
offsetYMax="75%"
35+
offsetYMin="-75%"
36+
slowerScrollRate={false}
37+
styleOuter={{
38+
border: 'solid red 2px',
39+
}}
40+
styleInner={{
41+
border: 'solid blue 2px',
42+
}}
43+
tag="figure"
44+
>
45+
<div className="foo" />
46+
</Parallax>
47+
</ParallaxProvider>,
48+
{
49+
createNodeMock,
50+
}
51+
)
52+
.toJSON();
53+
expect(tree).toMatchSnapshot();
54+
});
55+
1556
it('to throw if the ParallaxController is not available', () => {
1657
const node = document.createElement('div');
1758
// NOTE: hide error and react warning
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Expect the <Parallax> component to render correctly 1`] = `
4+
<figure
5+
className="parallax-outer class-foo"
6+
style={
7+
Object {
8+
"border": "solid red 2px",
9+
}
10+
}
11+
>
12+
<div
13+
className="parallax-inner"
14+
style={
15+
Object {
16+
"border": "solid blue 2px",
17+
}
18+
}
19+
>
20+
<div
21+
className="foo"
22+
/>
23+
</div>
24+
</figure>
25+
`;

0 commit comments

Comments
 (0)