Skip to content

Commit 0d7a98c

Browse files
committed
parallax provider test
1 parent 3534ac3 commit 0d7a98c

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

__tests__/ParallaxProvider.test.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* global describe, it */
2+
3+
import React from 'react';
4+
5+
import PropTypes from 'prop-types';
6+
import ReactDOM from 'react-dom';
7+
import ParallaxProvider from 'components/ParallaxProvider';
8+
import ParallaxController from 'libs/ParallaxController';
9+
10+
describe('A <ParallaxProvider>', () => {
11+
12+
// afterEach(() => )
13+
it('to render children', () => {
14+
const node = document.createElement('div');
15+
let child = jest.fn();
16+
const Child = () => {
17+
child();
18+
return <div />
19+
};
20+
21+
const render = () => {
22+
ReactDOM.render(
23+
<ParallaxProvider>
24+
<Child />
25+
</ParallaxProvider>,
26+
node
27+
);
28+
};
29+
30+
render();
31+
32+
expect(child).toBeCalled();
33+
});
34+
35+
it('to pass the controller context', () => {
36+
const node = document.createElement('div');
37+
38+
let rootCtx;
39+
const ContextChecker = (props, context) => {
40+
rootCtx = context;
41+
return null;
42+
};
43+
44+
const testController = ParallaxController.init();
45+
46+
ContextChecker.contextTypes = {
47+
parallaxController: PropTypes.shape({
48+
destroy: PropTypes.func.isRequired,
49+
update: PropTypes.func.isRequired,
50+
}),
51+
};
52+
53+
ReactDOM.render(
54+
<ParallaxProvider>
55+
<ContextChecker />
56+
</ParallaxProvider>,
57+
node
58+
);
59+
60+
// Expected methods and state
61+
expect(rootCtx.parallaxController).toBeInstanceOf(ParallaxController);
62+
});
63+
64+
it('to destroy the controller when unmounting', () => {
65+
const node = document.createElement('div');
66+
67+
global.ParallaxController = ParallaxController.init();
68+
global.ParallaxController.destroy = jest.fn();
69+
70+
ReactDOM.render(
71+
<ParallaxProvider>
72+
<div />
73+
</ParallaxProvider>,
74+
node
75+
);
76+
77+
ReactDOM.unmountComponentAtNode(node);
78+
79+
expect(global.ParallaxController.destroy).toBeCalled();
80+
});
81+
82+
it('to not init the controller on the server');
83+
84+
// it('to not init the controller on the server', () => {
85+
// const node = document.createElement('div');
86+
87+
// window = undefined;
88+
// let instance;
89+
90+
// ReactDOM.render(
91+
// <ParallaxProvider ref={ref => instance = ref}>
92+
// <div />
93+
// </ParallaxProvider>,
94+
// node
95+
// );
96+
97+
// expect(instance.parallaxController).toBeUndefined();
98+
// });
99+
});

0 commit comments

Comments
 (0)