- Mastering React Test:Driven Development
- Daniel Irvine
- 98字
- 2021-06-24 14:45:10
Finishing off the form with a submit button
It's a good time to add a submit button and perform a manual test to check what you've created. A submit button test is relatively simple. Add the following test to your test file:
it('has a submit button', () => {
render(<CustomerForm />);
const submitButton = container.querySelector(
'input[type="submit"]'
);
expect(submitButton).not.toBeNull();
});
Then, make that pass by adding in your submit button into the form, at the bottom:
<form id="customer" onSubmit={handleSubmit}>
...
<input type="submit" value="Add" />
</form>
Update your entrypoint in src/index.js to render a new CustomerForm instance, rather than an AppointmentsDayView, and you should be ready to manually test:

推薦閱讀