Skip to content

Commit

Permalink
updated propTypes for height and width to be union type of string and…
Browse files Browse the repository at this point in the history
… number. Also added jest test check no warnings happen when a string is used
  • Loading branch information
dcgudeman committed May 17, 2018
1 parent 00016c5 commit 23553d8
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/__tests__/react-loading.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { shallow } from 'enzyme';
import sinon from 'sinon';

import Loading from '../react-loading';

Expand Down Expand Up @@ -51,4 +52,12 @@ describe('test Loading component', () => {

expect(enzymeWrapper.instance().timeout).not.toEqual(undefined);
});

it('allows setting height and width with strings without propTypes warnings', () => {
const spyConsoleError = sinon.spy(console, 'error');
const enzymeWrapper = shallow(<Loading height={'20%'} width={'20%'} />);
expect(spyConsoleError.callCount).toEqual(0);
spyConsoleError.restore();
});

});
10 changes: 8 additions & 2 deletions lib/react-loading.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ export default class Loading extends Component {
color: PropTypes.string,
delay: PropTypes.number,
type: PropTypes.string,
height: PropTypes.number,
width: PropTypes.number,
height: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
width: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
};

static defaultProps = {
Expand Down
107 changes: 107 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"react-dom": ">=0.14.0",
"react-test-renderer": "^16.0.0",
"rimraf": "^2.6.1",
"sinon": "^5.0.7",
"webpack": "^3.8.1"
},
"jest": {
Expand Down

0 comments on commit 23553d8

Please sign in to comment.