Skip to content
All lessons

Tech Insights

This is how you mock components when testing react with jest:

// in your test file
jest.mock('../path/to/component/to/Component.js');

Create a __mocks__ folder in the same directory of the component you want to test and a file with the same name of the component inside it:

// __mocks__/Component.js
import React from 'react';
export default function mock() {
  return (<span>Component mock</span>);
}

Shared by

  • Tests

Book a call

Lessons like this one
shape how we build.

Tell us what you’re building. In one call, we’ll show you how our team would approach it.

Tell us what you’re building, and we’ll show you how we’d approach it.

Still prefer the good old email? Contact us