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 ...

Get Learning Behavior-driven Development with JavaScript now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.