Test that checkPropTypes does not throw or return a value
Andrew Clark committed
Feb 15, 2017 at 14:10 UTC
e4acd12a9b995410188c6a551b069c6583a88cca
2 files changed
+30
scripts/fiber/tests-passing.txt
+2
@@ -307,6 +307,8 @@ src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js
307
* does not blow up on key warning with undefined type
308
309
src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
310
+* does not return a value from a validator
311
+* does not throw if validator throws
312
* should warn for invalid strings
313
* should fail date and regexp correctly
314
* should not warn for valid values
src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
+28
@@ -106,6 +106,34 @@ describe('ReactPropTypes', () => {
106
ReactTestUtils = require('ReactTestUtils');
107
});
108
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
+
137
describe('Primitive Types', () => {
138
it('should warn for invalid strings', () => {
139
typeCheckFail(