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)

Using the browser JavaScript console


Other than the HTTP requests that the browser makes, Zombie doesn't output much else that may be interesting or useful while debugging for you to debug your application.

A good option, which provides far more flexibility and insight, is to run your application inside a real browser with developer tools and/or a debugger.

A particularly useful alternative for debugging issues that are encountered specifically in Zombie.js is to use the console.log() function inside your browser code (the code that, in the case of this app, sits inside the public/js directory).

As an example, suppose that you were having a problem with the to-do creation form: the alarm option was not correctly triggering the show and hide option of the alarm option pane. For this, we can introduce the following console.log statement in the public/js/todos.js file, in order to inspect the value of the ringAlarm variable: function hideOrShowDateTime().

  {
    var ringAlarm = $('input[name=alarm...