Skip to content

Commit a043ebb

Browse files
committed
Test that checkPropTypes does not throw or return a value
1 parent 165c974 commit a043ebb

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

scripts/fiber/tests-passing.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js
307307
* does not blow up on key warning with undefined type
308308

309309
src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
310+
* does not return a value from a validator
311+
* does not throw if validator throws
310312
* should warn for invalid strings
311313
* should fail date and regexp correctly
312314
* should not warn for valid values

src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,34 @@ describe('ReactPropTypes', () => {
106106
ReactTestUtils = require('ReactTestUtils');
107107
});
108108

109+
describe('checkPropTypes', () => {
110+
it('does not return a value from a validator', () => {
111+
spyOn(console, 'error');
112+
const propTypes = {
113+
foo(props, propName, componentName) {
114+
return new Error('some error');
115+
},
116+
};
117+
const props = { foo: 'foo' };
118+
const returnValue = PropTypes.checkPropTypes(propTypes, props, 'prop', 'testComponent', true);
119+
expect(console.error.calls.argsFor(0)[0]).toContain('some error');
120+
expect(returnValue).toBe(undefined);
121+
});
122+
123+
it('does not throw if validator throws', () => {
124+
spyOn(console, 'error');
125+
const propTypes = {
126+
foo(props, propName, componentName) {
127+
throw new Error('some error');
128+
},
129+
};
130+
const props = { foo: 'foo' };
131+
const returnValue = PropTypes.checkPropTypes(propTypes, props, 'prop', 'testComponent', true);
132+
expect(console.error.calls.argsFor(0)[0]).toContain('some error');
133+
expect(returnValue).toBe(undefined);
134+
});
135+
});
136+
109137
describe('Primitive Types', () => {
110138
it('should warn for invalid strings', () => {
111139
typeCheckFail(

0 commit comments

Comments
 (0)