You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.
While going through and updating to use the external prop-types package, I noticed that some of our tests were failing and couldn't figure out why. Eventually we found that the oddity in the tests were coming from the fact that the warning issued by the package is only called once, even if testing the component's propTypes with checkPropTypes multiple times. Take for example the following tests:
it('returns error if props[propName] is not passed', () => {
const propValue = null;
expect(() => PropTypes.checkPropTypes(Component.propTypes, { [propName]: propValue }, propName, componentName)).to.throw(Error);
});
it('returns error if any of the props[propName] is not a PropType.node', () => {
const propValue = shallow(<div>{{}}</div>).props().children;
expect(() => PropTypes.checkPropTypes(Component.propTypes, { [propName]: propValue }, propName, componentName)).to.throw(Error);
});
In this case, the first test passes as the package does warn (and we override console.warn/console.error to throw an error), but the second test fails as there isn't a warning, and thus an error isn't thrown.
We know that this is the case because if we change componentName to be a unique string in each case, the warning is displayed for each as expected.
The trouble here is that with using this external package, we're unsure as to how many false positives we have in our test suite due to this.
Should there a be a way to have the warning's call each time so that tests can test this more accurately?
The text was updated successfully, but these errors were encountered:
At ratehub we're maintaining a helper package for testing, check-prop-types. It mirrors this project's checkPropTypes function, but errors are returned (or thrown for assertPropTypes) instead of logged, and memoization is removed.
Alternately, there is a neat PR here using a callback to signal errors.
While going through and updating to use the external prop-types package, I noticed that some of our tests were failing and couldn't figure out why. Eventually we found that the oddity in the tests were coming from the fact that the warning issued by the package is only called once, even if testing the component's propTypes with checkPropTypes multiple times. Take for example the following tests:
In this case, the first test passes as the package does warn (and we override console.warn/console.error to throw an error), but the second test fails as there isn't a warning, and thus an error isn't thrown.
We know that this is the case because if we change componentName to be a unique string in each case, the warning is displayed for each as expected.
The trouble here is that with using this external package, we're unsure as to how many false positives we have in our test suite due to this.
Should there a be a way to have the warning's call each time so that tests can test this more accurately?
The text was updated successfully, but these errors were encountered: