Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit 0445b8b

Browse files
authored
Add test coverage for invalid validator warning (#86)
* Add test coverage for invalid validator warning * Fix invalid validator test name
1 parent 42d559d commit 0445b8b

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

__tests__/PropTypesDevelopmentReact15.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,23 @@ describe('PropTypesDevelopmentReact15', () => {
113113
});
114114

115115
describe('checkPropTypes', () => {
116+
it('should warn for invalid validators', () => {
117+
spyOn(console, 'error')
118+
const propTypes = { foo: undefined };
119+
const props = { foo: 'foo' };
120+
PropTypes.checkPropTypes(
121+
propTypes,
122+
props,
123+
'prop',
124+
'testComponent',
125+
null,
126+
);
127+
expect(console.error.calls.argsFor(0)[0]).toEqual(
128+
'Warning: Failed prop type: testComponent: prop type `foo` is invalid; ' +
129+
'it must be a function, usually from the `prop-types` package.'
130+
);
131+
});
132+
116133
it('does not return a value from a validator', () => {
117134
spyOn(console, 'error');
118135
const propTypes = {

__tests__/PropTypesDevelopmentStandalone-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,23 @@ describe('PropTypesDevelopmentStandalone', () => {
109109
});
110110

111111
describe('checkPropTypes', () => {
112+
it('should warn for invalid validators', () => {
113+
spyOn(console, 'error')
114+
const propTypes = { foo: undefined };
115+
const props = { foo: 'foo' };
116+
PropTypes.checkPropTypes(
117+
propTypes,
118+
props,
119+
'prop',
120+
'testComponent',
121+
null,
122+
);
123+
expect(console.error.calls.argsFor(0)[0]).toEqual(
124+
'Warning: Failed prop type: testComponent: prop type `foo` is invalid; ' +
125+
'it must be a function, usually from the `prop-types` package.'
126+
);
127+
});
128+
112129
it('does not return a value from a validator', () => {
113130
spyOn(console, 'error');
114131
const propTypes = {

0 commit comments

Comments
 (0)