February 2019
Intermediate to advanced
204 pages
4h 52m
English
So, what if there are multiple React components, and some components have already been tested? If we create snapshot testing, that will simply collect a bunch of snapshots. Isn’t that overkill?
Yes; absolutely. This is when mocking shines. An example is better than a thousand words. Let's consider the following React component. Consider a HeaderNav component that contains a Logo component, a Header component, and social media link components. We are using these components in our HeaderNav component, and we know that we have already tested the Header component. To avoid this, we can just mock the component that we do not want to include in the snapshot:
import React from "react";import Link from "react-router-dom/Link"; ...
Read now
Unlock full access