Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions __tests__/PropTypesDevelopmentStandalone-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,27 @@ describe('PropTypesDevelopmentStandalone', () => {
expectInvalidValidatorWarning(PropTypes.exact({ bar: 'true' }), 'string');
expectInvalidValidatorWarning(PropTypes.exact({ bar: null }), 'null');
});

it('calls the passed in warning logger', () => {
const warningLogger = jest.fn()
const propTypes = {
foo(props, propName, componentName) {
throw new Error('some error');
},
};
const props = {foo: 'foo'};
const returnValue = PropTypes.checkPropTypes(
propTypes,
props,
'prop',
'testComponent',
null,
warningLogger,
);

expect(warningLogger).toBeCalledWith('Failed prop type: some error');
expect(returnValue).toBe(undefined);
});
});

describe('resetWarningCache', () => {
Expand All @@ -262,6 +283,7 @@ describe('PropTypesDevelopmentStandalone', () => {
'testComponent',
null,
);

PropTypes.resetWarningCache();
PropTypes.checkPropTypes(
propTypes,
Expand Down
3 changes: 2 additions & 1 deletion checkPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ function checkPropTypes(typeSpecs, values, location, componentName, getStack) {

var stack = getStack ? getStack() : '';

printWarning(
var warningLogger = arguments.length > 5 ? arguments[5] : printWarning;
warningLogger(
'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
);
}
Expand Down