How to test React PropTypes through Jest?

Posted by Rohit Kumar | Updated on

Want to test React PropTypes through Jest? The short answer is that you should replace the console.{method} for the duration of the test. The common approach is to use spies. In this particular case, you might want to use stubs to prevent the output.

Here is an example implementation using Sinon.js:

In this example DataName component will throw an error when initialised with a timestamp value that does not represent a precise date (12:00:00 AM).

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers