Chapter 19. Project: Checking passwords with Jest

 

This chapter covers

  • Project structure and Webpack configuration
  • The host HTML file
  • Implementing a strong password module
  • Creating Jest tests
  • Implementing the Password component and UI

This project focuses on building a UI, working with modules, and testing with Jest, along with other React-related techniques such as component composition, ES6 syntax, state, properties, and so on. Recall that chapter 16 dealt with testing; you used a password widget as an example of unit testing and UI testing. In this project, you’ll build the widget itself to check, verify, and generate new passwords. Along the way, I’ll explain testing again, here and there, in an expanded format.

The widget has a Save button that’s disabled by default but becomes enabled when the password is strong enough (according to the preset rules), as shown in figure 19.1. In addition, the Generate button lets you create a strong (according to the criteria) password. As each rule is satisfied, it’s crossed out. There’s also a Show Password check box that hides/shows the password, just as in most macOS interfaces (see figure 19.2).

Figure 19.1. Password widget that lets you enter a password or autogenerate one that meets the given strength criteria
Figure 19.2. The widget with some of the criteria fulfilled and the password visible

The parent component is called Password, and the child components are listed here:

19.1. Project structure and Webpack configuration

19.2. The host HTML file

19.3. Implementing a strong password module

19.4. Implementing the Password component

19.5. Putting it into action

19.6. Homework

19.7. Summary