jest-prop-type-error
jest-prop-type-error copied to clipboard
The test suite passes even if a prop types error is present
Describe the bug The test suite passes even if a prop type error is present.
To Reproduce This is my setup files
const error = console.error;
console.error = (message, ...args) => {
if (/(Invalid prop|Failed prop type)/gi.test(message)) {
throw new Error(message);
}
error.apply(console, [message, ...args]);
};
Expected behavior The test suite doesn't pass
Actual behavior The test suite passes and an error is displayed in the console
Screenshots
Versions:
- prop-types: 15.7.2
- React: 17.0.1
- Jest: 26.6.3
- Node: 14.15.3
Any update on it?
so react now uses sprintf style strings
a "fix" is message = require('util').format(message, ...args);
in index.js
(I did some debugging, it'll be like https://github.com/facebook/react/blob/cae635054e17a6f107a39d328649137b83f25972/fixtures/legacy-jsx-runtimes/react-15/cjs/react-jsx-dev-runtime.development.js#L296 but not that exact line)
The other problem is that the message is only spit out once, so it won't fail multiple tests
I'm going to do another route, but figured i'd share it for usefulness.
https://github.com/facebook/prop-types/blob/be165febc8133dfbe2c45133db6d25664dd68ad8/checkPropTypes.js would be the actual errors
Hey folks. I am seeing the same issue since I upgraded to React 17. Any updates on this?
Since this repository is not being maintained as far as we can see, take the initiative and create a new npm package to handle these cases. This version is compatible with the latest version of Jest.
https://github.com/vicasas/jest-prop-types