From now on, all the test development will follow the testing library. How does that translate into the test that we have? So instead of having just the P, let's start with the label text. We will have a label for last name, we'll have a label for first name. We will also give a news, the advantage of the button being a specific HTML element, and we'll click it, and that's pretty much it.
A small note about labels. People tend to mock me because I put labels on everything that I do. Why is it? Because it is a small piece of paper that is attached to an object, and it gives information about it. It stands for computers, it stands for cables, it stands for anything. In particular, for web development, a label in an HTML element will represent a caption for an item that is on the document. So you will be able to access it. You will be able to reach it within your DOM.
So let's start typing on the forms that we have. When we do so, we can increase the complexity of the test that we just built. So we will also be able to give the semantic meaning of having a form because I didn't have a form before, I just had loose elements spread out in the document. So let's have a form within the document. Let's have the first name, let's click it, let's type things on it, let's use and mimic the interactions that the user will do with the page.
But this gives us a problem, which is the input molecule, the text input molecule, it was not prepared to receive labels, it was not prepared to receive more information than the one we already gave it. So we'll need to come back, update the text input molecule, and always having in mind accessibility. So all of the queries that you're doing, all of the tests that you're writing, you're doing so, thinking about how will I be able to access this, how will I be able to reach it? The testing library is very helpful when it comes to telling us what is wrong with our tests. So let's just fix it. Nothing, nothing more, nothing less. We fix it. It looks happy and content with it. And all the tests pass. So we were able to do not only some refactor, but also some extension of the code that we already had. It's good. We already have that form with the first name and last name and then the button. But if you remember from the form, it will request more information about personal data. So maybe it is refactoring time. It should be fine.
Comments