mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
Test that checkPropTypes does not throw or return a value
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user