Skip to content

Commit

Permalink
test(slider): add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dackmin committed Jun 3, 2019
1 parent 870faec commit 8b52d93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class Slider extends React.Component {
});
}

onResize = (e) => {
onResize = /* istanbul ignore next */ () => {
this.setState({
parentWidth: this.slideRef?.offsetWidth,
});
Expand Down
14 changes: 14 additions & 0 deletions tests/Slider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ describe('<Slider />', () => {
expect(component.state('precision')).toBe(1);
});

it('should update internal value when value prop changes', () => {
const component = shallow(<Slider />);
expect(component.state('value')).toBe(0);
component.setProps({ value: 10 });
expect(component.state('value')).toBe(10);
});

it('should return a value rounded to the correct step & precision', () => {
const component = shallow(<Slider min={0} max={100} step={1} />);
expect(component.instance().getValue(15.6)).toBe(16);
Expand Down Expand Up @@ -119,4 +126,11 @@ describe('<Slider />', () => {
.toBe('<span class="label">label</span>');
});

it('should listen for page resize event when autoResize is true', () => {
const map = {};
document.addEventListener = (event, cb) => map[event] = sinon.spy(cb);
mount(<Slider autoResize={true} />);
expect(map.resize).toBeDefined();
});

});

0 comments on commit 8b52d93

Please sign in to comment.