Write Good Tests With Mocha

Learn to use the Mocha framework and the Node.js assert library to write, automate, and organize tests in Javascript.

Start[missing "en.views.course_landing_page.learn-javascript-unit-testing.course_illustration" translation]
Chevron Left Icon
Automate and Organize Tests
Lesson 1 of 2
Chevron Right Icon
  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: [...] The second (and recommended) method is ...

  4. 4

    In Mocha we group tests using the [...] function and define tests using the [...] function. These two functions can be used to make your test suite complete, maintainable, and expressive ...

  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 [...] method provided by Node.js. In programmin...

  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 [...] 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...

  9. 9

    You can now write tests with Mocha and Node's [...] ! In this lesson you learned to: - Install Mocha with npm - Organize tests with [...] and [...] - Ensure your tests are isolated and expre...

  1. 1

    A good test framework is fast, complete, reliable, isolated, maintainable, and expressive . In this lesson you will learn how to use Node's [...] library to write more expressive t...

  2. 2

    As a Node module, [...] can be imported at the top of your files with [...] The functions in the [...] library compare values and throw errors as needed using one function call. The small,...

  3. 3

    You can use [...] for most verifications, but sometimes it can be difficult to determine the condition you are evaluating. Read the example code below. Will this assertion throw an error? [...]...

  4. 4

    Take a look at the code below. Will these assertions throw errors? [...] - The first assertion will not throw an error because it uses loose ( [...] ) equality. It performs a type conversion wh...

  5. 5

    Do you think these assertions will throw errors? [...]

    Both assertions will throw an error because distinct objects are not considered equal when using either loose or strict equality in JavaS...

  6. 6

    In the last exercise you used [...] to compare the values of two objects with loose equality. Arrays are also objects, so [...] also compares their values with loose equality. [...] If you'...

  7. 7

    Node’s [...] library includes more than the four methods covered so far. You can find them all in the Node.js documentation .

    Many of the methods can be implemented using other methods, like ...

  8. 8

    You can now write tests with Node's [...] library! In this lesson you learned to: - Check for loose ( [...] ) equality with [...] - Check for strict ( [...] ) equality with [...] - Check the ...

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

Write Good Tests With Mocha

Start[missing "en.views.course_landing_page.learn-javascript-unit-testing.course_illustration" translation]