Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Events
Videos
Audiobooks
Packt Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Learning Behavior-driven development with Javascript

You're reading from   Learning Behavior-driven development with Javascript Create powerful yet simple-to-code BDD test suites in JavaScript using the most popular tools in the community

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher
ISBN-13 9781784392642
Length 392 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Enrique Javier A Rubio Enrique Javier A Rubio
Author Profile Icon Enrique Javier A Rubio
Enrique Javier A Rubio
Arrow right icon
View More author details
Toc

Testing asynchronous features

If you have made the tests pass, you are probably thinking that you are done. But actually, you are not. The problem is that we have designed a synchronous API. This is not feasible in a JS application, because JS is single-threaded. Any I/O will cause our system to block, and we need to process the requests one at a time. This is not acceptable in a server or in a UI application. So, we need to change our design to use an asynchronous API, but how do we test an asynchronous API?

Testing a callback-based API

Instead of returning the value directly, we can change our API to use callbacks. The same thing applies to our DAO. After all, the DAO will perform IO, so it needs to be asynchronous. So, let's change our test. For this, we first need to change the setup and action:

context('Given that the order is empty', function () {
    var result;
    beforeEach(function (done) {
      this.orderId = 'some empty order id';
      this.orderDAO...
lock icon The rest of the chapter is locked
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Learning Behavior-driven development with Javascript
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
Modal Close icon
Modal Close icon