Test-driving callback props
In this section, we’ll introduce a new extension function, propsOf
, that reaches into a mocked child component and returns the props that were passed to it. We’ll use this to get hold of the onSave
callback prop value and invoke it from our test, mimicking what would happen if the real CustomerForm
had been submitted.
It’s worth revisiting why this is something we’d like to do. Reaching into a component and calling the prop directly seems complicated. However, the alternative is more complicated and more brittle.
The test we want to write next is the one that asserts that the AppointmentFormLoader
component is shown after CustomerForm
has been submitted and a new customer has been saved:
it("displays the AppointmentFormLoader after the CustomerForm is submitted", async () => { // ... });
Now, imagine that we wanted to test this without a mocked CustomerForm
. We would need to fill in the real...