Return to site

REACT FIRE 🔥 event: How to unit test a text input field

· react,fullstack,testing

Imagine you have a simple field formatting a credit card number in packets of 4 digits

🖼️GUI:

 

⚙️Controller:

 

A unit test follows the '3 As' rule: Arrange, Act, and Assert.

Let's follow these steps in testing a React input field by faking the input filling, then reading it and comparing the outcome with what is expected.

🧪Unit test:

 

👨💻Code repo: