Mocha is a framework that runs your tests. You should split your tests into several files according to the functional areas you want to cover, and then describe each feature and define the necessary tests for each feature.
For each of these test groups, you optionally specify callback to be invoked using before
, beforeEach
, after
, and afterEach
. These callbacks are where the setup and teardown functions are specified. Each of these teardown or setup functions can be either synchronous or asynchronous. Furthermore, each of the tests themselves can be made to function asynchronously simply by passing a callback to the test, which will be invoked once the test is complete.
For asynchronous tests, Mocha reserves a default timeout of 2 seconds that you can override globally or on a per-test basis.
In the following chapter we will see how you can start using Zombie.js to simulate and manipulate a browser.