Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Node.js By Example

You're reading from   Node.js By Example Learn to use Node.js by creating a fully functional social network

Arrow left icon
Product type Paperback
Published in May 2015
Publisher Packt
ISBN-13 9781784395711
Length 220 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Table of Contents (13) Chapters Close

Preface 1. Node.js Fundamentals FREE CHAPTER 2. Architecting the Project 3. Managing Assets 4. Developing the Model-View-Controller Layers 5. Managing Users 6. Adding Friendship Capabilities 7. Posting Content 8. Creating Pages and Events 9. Tagging, Sharing, and Liking 10. Adding Real-time Chat 11. Testing the User Interface Index

Testing user registration


Let's use the setup built in the previous sections and write an actual test. Let's say that we want to make sure that our registering page works. The following are the two processes that we want to capture with our test:

  • Filling the form with wrong data and making sure that the application shows an error message

  • Filling the form with correct data and seeing a successful message

We are going to use PhantomJS as our headless (virtual) browser. So, all we have to do is load our registration page and simulate user interactions, such as typing in the fields and pressing the buttons.

Simulating user interaction

There are a couple of issues that we are going to resolve. The first one is the actual simulation of user actions. From a JavaScript point of view, these actions are translated to events dispatched by some particular DOM elements. The following helper method will become a part of the tests/spec.js file:

describe("Testing", function () {

  var trigger = function(element...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime