mardi 27 août 2019

React and Jest - testing a component using PropTypes.instanceOf

I have a React component using a property defined as an instance of an ES6 class with PropTypes.instanceOf(MyClass).isRequired. When testing using an instance of a mock class, I always get a console error: Warning: Failed prop type.

I tried various techniques based on https://jestjs.io/docs/en/es6-class-mocks and https://reactjs.org/docs/testing-recipes.html , but none of them work: the type never matches what is expected (even when the class name is the same).

How would I test the component using a mock class without removing the type checking ?

Aucun commentaire:

Enregistrer un commentaire