Automate and Organize Tests
Lesson 1 of 2
  1. 1
    Testing is an essential part of development. When used properly, testing can catch and identify issues with your implementation code before you deploy it to users. Instead of testing every function…
  2. 2
    Before writing any tests you’ll need to use Node.js and npm to set up a JavaScript project and install Mocha. - Node allows you to run JavaScript in the terminal - npm is a Node tool that a…
  3. 3
    After installing Mocha as a dependency we can run it in two ways. The first (and more tedious) method is to call it directly from node_modules: $ ./node_modules/mocha/bin/mocha The second (a…
  4. 4
    In Mocha we group tests using the describe function and define tests using the it function. These two functions can be used to make your test suite complete, maintainable, and expressive in t…
  5. 5
    In the last exercise, you learned how to organize and automate tests using the Mocha test framework. To write the tests themselves, we can use the assert.ok method provided by Node.js. In programm…
  6. 6
    In this exercise you will be separating a test into setup, exercise, and verify phases. This distinct and well-defined separation of steps makes your test more reliable, maintainable, a…
  7. 7
    Some tests require a fourth phase called teardown. This step makes your test isolated. - Teardown - reset any conditions that were changed during the test A test, like the example in this e…
  8. 8
    Using teardown in the it block made your test isolated, but not reliable. If the system encounters an error before it reaches the teardown, it will not execute that phase. In the previous exam…
  9. 9
    You can now write tests with Mocha and Node’s assert.ok() ! In this lesson you learned to: - Install Mocha with npm - Organize tests with describe() and it() - Ensure your tests are isolated and e…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo