<p>This is how you mock components when testing react with <code>jest</code>:</p>
<p><code>// in your test file
jest.mock('../path/to/component/to/Component.js');</code></p>
<p>Create a <code>__mocks__</code> folder in the same directory of the component you want to test and a file with the same name of the component inside it:</p>
<p><code>// __mocks__/Component.js
import React from 'react';
export default function mock() {
return (<span>Component mock</span>);
}</code></p>
By clicking “Accept cookies”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage and assist in our marketing efforts. Check our privacy policies.
By clicking “Accept all”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage and assist in our marketing efforts. Check our privacy policies.