jest-prop-type-error icon indicating copy to clipboard operation
jest-prop-type-error copied to clipboard

The test suite passes even if a prop types error is present

Open emilioSp opened this issue 4 years ago • 5 comments

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 image

Versions:

  • prop-types: 15.7.2
  • React: 17.0.1
  • Jest: 26.6.3
  • Node: 14.15.3

emilioSp avatar Jan 27 '21 17:01 emilioSp

Any update on it?

raualvron avatar Sep 28 '21 06:09 raualvron

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.

halkeye avatar Dec 05 '21 01:12 halkeye

https://github.com/facebook/prop-types/blob/be165febc8133dfbe2c45133db6d25664dd68ad8/checkPropTypes.js would be the actual errors

halkeye avatar Dec 05 '21 01:12 halkeye

Hey folks. I am seeing the same issue since I upgraded to React 17. Any updates on this?

svenjungnickel avatar Jan 14 '22 20:01 svenjungnickel

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

vicasas avatar Jan 20 '22 21:01 vicasas