Test that checkPropTypes does not throw or return a value

This commit is contained in:
Andrew Clark
2017-02-23 11:14:14 -08:00
parent f1f92b89b4
commit 35306576bf
2 changed files with 30 additions and 0 deletions
+2
View File
@@ -307,6 +307,8 @@ src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js
* does not blow up on key warning with undefined type
src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
* does not return a value from a validator
* does not throw if validator throws
* should warn for invalid strings
* should fail date and regexp correctly
* should not warn for valid values
@@ -106,6 +106,34 @@ describe('ReactPropTypes', () => {
ReactTestUtils = require('ReactTestUtils');
});
describe('checkPropTypes', () => {
it('does not return a value from a validator', () => {
spyOn(console, 'error');
const propTypes = {
foo(props, propName, componentName) {
return new Error('some error');
},
};
const props = { foo: 'foo' };
const returnValue = PropTypes.checkPropTypes(propTypes, props, 'prop', 'testComponent', true);
expect(console.error.calls.argsFor(0)[0]).toContain('some error');
expect(returnValue).toBe(undefined);
});
it('does not throw if validator throws', () => {
spyOn(console, 'error');
const propTypes = {
foo(props, propName, componentName) {
throw new Error('some error');
},
};
const props = { foo: 'foo' };
const returnValue = PropTypes.checkPropTypes(propTypes, props, 'prop', 'testComponent', true);
expect(console.error.calls.argsFor(0)[0]).toContain('some error');
expect(returnValue).toBe(undefined);
});
});
describe('Primitive Types', () => {
it('should warn for invalid strings', () => {
typeCheckFail(