Writing and executing unit tests in JavaScript
It's important to develop an application over time and not break functionality later. It doesn't matter if the application was developed with C#, Java, Python, or JavaScript.
There are several client-side unit testing frameworks out there, the most prominent ones being:
- Jasmine
- AVA
- Mocha
- Jest
- QUnit
Every testing framework has its ups and downs. We'll use QUnit in this chapter. QUnit was developed by jQuery developers and is used to test jQuery methods. jQuery depends on QUnit not breaking over time, when developers add new functions and break completely non-irrelevant parts of the framework.
Note
The example project can be found at https://github.com/polatengin/B05277/tree/master/Chapter18/4-GettingStartedQUnit.
Getting ready
It's so easy to create a basic test setup with QUnit. Let's create a HTML5 file and add several elements to it, as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport...