I am facing the following warning/issue with React and Jest + Enzyme testing in the console:
console.error node_modules/react/cjs/react.development.js:172
Warning: React.createElement: type is invalid -- expected a string (for built-in components)
or a class/function (for composite components) but got: object.
The production code is using a bare version of a component (exported by a HoC).
The lib is giving the possibility of accessing the original BaseComponent if needed, as I do. Example of the exported component from the lib/HoC is the following:
EnrichedComponent.WrappedComponent = BaseComponent;
So I access like this (it's a button)
const { WrappedComponent: BaseButton } = Button;
// usage example
<BaseButton>
hi!
</BaseButton>
In the test I need to mock the lib and the exported parts, so I do the following:
jest.mock('myLib', () => ({
Button: {
WrappedComponent: 'base-button-component',
displayName: 'button-component',
},
}));
The issue happens in testing. I am able to test it with no failure, but I've got the above mentioned warning.
Any idea? Is it something I should care about or is not worth?
Aucun commentaire:
Enregistrer un commentaire