Exercise Tuesday

Goal: Practice using Jest to run your unit tests. Aim for 100% coverage of your code. Continue using webpack.

Warm Up


  • Describe the Red-Green-Refactor workflow. How can this workflow help us write good code?
  • What is Jest? Why is unit testing important?
  • Why should we use before and after blocks?

Code


Test It Out

Choose an application you built in Intro (such as Roman Numeral, Pig Dice, or Triangle Tracker). Refactor the application to include the following:

  • Complete unit tests with Jest. Aim for 100% test coverage.
  • Complete separation of logic (UI logic in one file, business logic in another). You may even need to refactor some of your logic to make it more testable! If you aren't able to test UI logic, consider ways that logic could be refactored and moved into your business logic file.

Practice with Jest and testing is your top priority!

Sudoku Checker

Sudoku is a game where players must fill in a 9 x 9 board with the numbers 1 through 9. The Sudoku board looks like this:

sudoku-board-example

Create an application that checks if a completed Sudoku puzzle is “legal.” In other words, it should ensure the following rules are met:

  • Each row contains all numbers from 1 to 9 with no repeats.
  • Each column contains all numbers from 1 to 9 with no repeats.
  • Further Exploration: Each of the nine 3 x 3 grids contain all numbers from 1 to 9 with no repeats.

Focus on the business logic and make sure to test the logic thoroughly before implementing any user interface logic.

Testing and Solving Project Euler Problems

Project Euler is an archive of math problems that can be solved using programming languages such as JavaScript. The difficulty of these problems ranges from fairly simple to extremely challenging. Try solving a few Project Euler problems, taking care to fully test your code. You do not need to implement user interface logic to solve these problems; instead, focus on business logic and unit testing.

Peer Code Review


  • Specs were committed before code.
  • Business logic has 100% line coverage with Jest.
  • Dependencies are managed with npm.
  • webpack is used to lint, bundle, and process code.
  • Project demonstrates understanding of week's concepts. If prompted, you are able to discuss your code with an instructor using correct terminology.

Lesson 35 of 48
Last updated more than 3 months ago.