Book Image

Learning Behavior-driven development with Javascript

Book Image

Learning Behavior-driven development with Javascript

Overview of this book

Table of Contents (17 chapters)
Learning Behavior-driven Development with JavaScript
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Organizing our test code


We will continue coding our tests, assuming that our API uses promises but that the DAO uses callbacks. If you tried to make your first scenario pass, then you would end up with something similar to what I have in my project in the lib/orders.js file:

var Q = require('q');

module.exports = function () {
  return {
    display: function (orderId) {
      return Q.fulfill({
        items: [],
        totalPrice: 0,
        actions: [
          {
            action: 'append-beverage',
            target: orderId,
            parameters: {
              beverageRef: null,
              quantity: 0
            }
          }
        ]
      });
    }
  };
};

No orderDAO anywhere! In fact, we can remove all references to orderDAO in the setup or our test! What happened is that we introduced it prematurely. This is something we would not have done in real circumstances but, for the purposes of this book, it was very convenient.

Tip

On the other hand, start thinking of the high...