Chapter 14. Unit testing with QUnit

 

This chapter covers

  • Why testing is important
  • What unit testing means
  • Installing QUnit
  • Testing your JavaScript code with QUnit
  • How to create a complete test suite with QUnit

The previous chapter was the last discussing concepts strictly related to the jQuery core. Deferred and Promise might have been tough arguments to learn but, hopefully, with our help the process has gone smoothly.

It’s now time for you to enhance your skills even further. In this chapter you’ll learn other tools and techniques that every pro must know. You’ll apply them to code written using jQuery, but you can reuse this knowledge with any code written in JavaScript. Testing is an essential concept to master if you’re working in a team or on anything that isn’t for your personal use only.

Important topics that you’ll explore in this chapter are tests and how to make assertions. An assertion is a way to verify that your code works correctly and your assumptions are respected. Stated another way, an assertion verifies that a function returns the value you expect given a set of inputs, or that the value of a variable or property of an object is what you expect after running some operations on it.

14.1. Why is testing important?

14.2. Getting started with QUnit

14.3. Creating tests for synchronous code

14.4. Testing your code using assertions

14.5. How to test asynchronous tasks

14.6. noglobals and notrycatch

14.7. Group your tests in modules

14.8. Configuring QUnit

14.9. An example test suite

14.10. Summary

sitemap