Exercise Tuesday

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

Warm Up

  • What is Jasmine? Why is unit testing important?
  • What is the difference between Karma and Jasmine? What benefits does Karma provide?
  • Why should we use before and after blocks?


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 Jasmine. Aim for 100% test coverage.
  • Continuous testing with Karma.
  • 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 Jasmine and testing is your top priority!

Further Exploration

  • Update Karma to provide support for other browsers.
  • Set up Istanbul.js to ensure you have 100% test coverage. You'll need to do some research on your own to get Instanbul.js up and running with Jasmine and Karma. This is a good opportunity to practice configuring your package.json file on your own.
  • Do your own research on the differences between Jasmine and Mocha/Chai. Both testing frameworks are very popular and have many similarities. (If you have the time, set up a testing environment with Mocha/Chai/Karma and try it out!)

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:


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 is thoroughly tested with Jasmine.
  • Karma is correctly configured.
  • 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.