May 2019
Intermediate to advanced
496 pages
10h 38m
English
Our components are defined using const, which theoretically means we can't change their value. For example:
export const AppointmentForm = ...
So, how can we stub a value that shouldn't change? There's a simple trick to stubbing these kinds of components. We need to import them differently. Usually, we would do this:
import { AppointmentForm } from '../src/AppointmentForm';
Instead, we will use a namespace import:
import * as AppointmentFormExports from '../src/AppointmentForm';
What we get from this is an object, AppointmentFormExports, with an AppointmentForm property is safe to reassign, as you'll see in the following test.
This technique won't work for modules from other packages. For that, you'll need to use ...
Read now
Unlock full access