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)

Chapter 8. Testing AJAX

In this book, we have tested the filling of text fields on a form, clicking on buttons, and the resulting HTML document. This makes us ready to test a traditional form-based request-response application, but typical modern applications are usually more complex than that as they make use of asynchronous HTTP requests, that somehow update the document without having to refresh it. This is because they use AJAX.

Our application emits AJAX requests when presented with the to-do item list page; a user can drag an item and drop it in the new position. The code that we placed in the public/js/todos.js file catches the change and calls the server /todos/sort URL, changing the item order in the database.

Let's see how we can use Zombie to test this drag-and-drop feature. The topics covered in this chapter include:

  • Using Zombie to trigger an AJAX call

  • Using Zombie to test the result of an AJAX call

By the end of this section, you will know how to use Zombie to test an application...