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! 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
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Deploying Node.js

You're reading from   Deploying Node.js Learn how to build, test, deploy, monitor, and maintain your Node.js applications at scale

Arrow left icon
Product type Paperback
Published in Jul 2015
Publisher
ISBN-13 9781783981403
Length 274 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Sandro Pasquali Sandro Pasquali
Author Profile Icon Sandro Pasquali
Sandro Pasquali
Arrow right icon
View More author details
Toc

Testing with Mocha, Chai, Sinon, and npm


One of the great benefits of writing tests for your code is that you will be forced to think through how what you've written works. A test that is difficult to write might indicate code that is difficult to understand. On the other hand, comprehensive coverage with good tests helps others (and you) understand how an application works.

There are at least three notions to consider when setting up your test environment.

The purpose of testing is to make comparisons between the value of what is received and what is expected by your application code. As we saw earlier, Node's assert module is designed for this purpose, but its functionality is limited to individual, isolated assertions. We'll use the Chai library (http://chaijs.com), which provides you with a richer choice of languages and idioms to make assertions with.

It is not unusual for an application to be covered by several hundred tests. When assertions are grouped, say by feature or business unit...

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
Banner background image