Book Image

Using Node.js for UI Testing

By : Pedro Teixeira
Book Image

Using Node.js for UI Testing

By: Pedro Teixeira

Overview of this book

<p>Automating tests for your user interfaces has always been the holy grail of programming. Now, using Zombie.js and Mocha you can create and quickly run your tests, allowing you to test even small changes. Increase your confidence in the code and minimize the number of times you have to use a real browser while you develop.</p> <p>"Using Node.js for UI Testing" is a quick and thorough guide on how to automatically test your web app, keeping it rock solid and bug-free. You will learn how to simulate complex user behaviour and verify that your application behaves correctly.</p> <p>You will create a web app in Node.js that uses complex user interactions and AJAX; by the end you will be able to fully test it from the command-line. Then you will start creating the user interface tests for this application using Mocha as a framework and Zombie.js as a headless browser.</p> <p>You will also create a complete test suite, module by module, testing simple and complex user interactions.</p>
Table of Contents (15 chapters)

Summary


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.