unexpected icon indicating copy to clipboard operation
unexpected copied to clipboard

Assertions for propType warnings

Open ezmiller opened this issue 8 years ago • 3 comments

Have you ever thought about adding an assertion for propType warnings on a React component? One method for doing that in general is illustrated here, but wouldn't it be useful to have a dedicated assertion. In general, it seems to me that testing propType warnings is probably valuable, if one is taking their use seriously.

ezmiller avatar May 26 '17 15:05 ezmiller

I like this idea. At best if you can test both positively or negatively, to ascertain that it will complain where you need it to, and leave it where it shouldn't.

gertsonderby avatar May 26 '17 19:05 gertsonderby

It should be possible to create an assertion that mocks console.error.

I have earlier been thinking about doing property based testing based on the prop types using unexpected-check. The challenge is that the prop types won't reveal any information about themselves, so you need something like https://github.com/reactjs/react-docgen to get the prop types. But it would be very cool just to say that a component shouldn't crash for valid prop types.

sunesimonsen avatar May 27 '17 11:05 sunesimonsen

Isn't the original idea covered by https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md?

papandreou avatar Jan 20 '19 23:01 papandreou