Skip to content

Commit 4be1a61

Browse files
committed
Merge branch 'master' of https://github.com/oslabs-beta/reactime
2 parents d4367d3 + 9919e47 commit 4be1a61

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/app/__tests__/MainSlider.test.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* eslint-disable react/jsx-props-no-spreading */
2+
import { shallow, configure } from 'enzyme';
3+
import React from 'react';
4+
import Adapter from 'enzyme-adapter-react-16';
5+
import Slider from 'rc-slider';
6+
import Tooltip from 'rc-tooltip';
7+
import MainSlider from '../components/MainSlider';
8+
9+
import { useStoreContext } from '../store';
10+
11+
configure({ adapter: new Adapter() });
12+
13+
jest.mock('../store');
14+
// the handle function in MainSlider returns out a Tooltip Component
15+
const handle = Tooltip;
16+
17+
describe('Unit testing for MainSlider.jsx', () => {
18+
let wrapper;
19+
const props = {
20+
snapshotsLength: 1,
21+
};
22+
23+
const state = {
24+
tabs: {
25+
100: {
26+
sliderIndex: 1,
27+
},
28+
},
29+
currentTab: 100,
30+
};
31+
32+
const dispatch = jest.fn();
33+
useStoreContext.mockImplementation(() => [state, dispatch]);
34+
35+
beforeEach(() => {
36+
wrapper = shallow(<MainSlider {...props} />);
37+
dispatch.mockClear();
38+
});
39+
it('Component should return <Slider /> component from rc-slider library', () => {
40+
expect(wrapper.type()).toEqual(Slider);
41+
});
42+
it('Component should have min, max, value, and handle props', () => {
43+
expect(wrapper.props()).toHaveProperty('min');
44+
expect(wrapper.props()).toHaveProperty('max');
45+
expect(wrapper.props()).toHaveProperty('value');
46+
expect(wrapper.props()).toHaveProperty('handle');
47+
});
48+
it('Prop type tests on component', () => {
49+
expect(typeof wrapper.prop('min')).toEqual('number');
50+
expect(typeof wrapper.prop('max')).toEqual('number');
51+
expect(typeof wrapper.prop('value')).toEqual('number');
52+
expect(typeof wrapper.prop('handle')).toEqual('function');
53+
});
54+
55+
describe('Testing for handle functional component', () => {
56+
// this doesnt work, not sure how to implement yet
57+
// the handle function should return a Tooltip component
58+
// eslint-disable-next-line jest/no-test-prefixes
59+
// eslint-disable-next-line jest/no-disabled-tests
60+
it.skip('handle prop should return <Tooltip /> component from rc-tooltip library', () => {
61+
expect(wrapper.prop('handle')()).toEqual(handle);
62+
});
63+
});
64+
});

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"target": "es5",
66
"jsx": "react",
77
"allowJs": true,
8-
"types": ["chrome", "jest", "node"]
8+
"types": ["chrome", "jest", "node"],
9+
"esModuleInterop": true
910
}
1011
}

0 commit comments

Comments
 (0)