Summary
In this chapter, you learned how to create an HTML form with text boxes. You wrote tests for the form
element, and for input
elements of types text
and submit
.
Although the text box is about the most basic input element there is, we’ve taken this opportunity to dig much deeper into test-driven React. We’ve discovered the intricacies of raising submit
and change
events via JSDOM, such as ensuring that event.preventDefault()
is called on the event to avoid a browser page transition.
We’ve also gone much further with Jest. We extracted common test logic into modules, used nested describe
blocks, and built assertions using DOM’s Form API.
In the next chapter, we’ll test-drive a more complicated form example: a form with select boxes and radio buttons.