May 2019
Intermediate to advanced
496 pages
10h 38m
English
To move the expectation under the Act phase of the test, we can introduce a variable to store the firstName that's passed into the onSubmit function. We then write the expectation against that stored value.
Let's do that now. Modify the saves existing value when submitted test-generator function in test/CustomerForm.test.js:
const itSubmitsExistingValue = fieldName => it('saves existing value when submitted', async () => { let submitArg; render(<CustomerForm { ...{[fieldName]: 'value'} } onSubmit={customer => submitArg = customer} />); ReactTestUtils.Simulate.submit(form('customer')); expect(submitArg[fieldName]).toEqual('value'); });
The submitArg variable is assigned within our onSubmit handler, and then asserted ...
Read now
Unlock full access