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

Testing slave resources


Although we have tested the main HAL document for an order, we are still not done. We have discovered that we need to create more HAL resources, order items, and actions. We need to write tests for them too.

The order actions

As we saw earlier, each action has been extracted to a form resource. How do form resources look?

Let's start with the /orders/:orderId/place-order-form resource. We will need a new feature for this, since accessing a form resource is a different operation from accessing the order from the consumer's point of view.

Let's create a test/get_placeOrderForm.js test suite:

'use strict';

var chai = require('chai'),
    expect = chai.expect,
    Q = require('q');

chai.use(require("sinon-chai"));
chai.use(require("chai-as-promised"));

describe('GET /order/:orderId/place-order-form', function () {
  beforeEach(function () {
    this.orderId = "<some order id>";
    this.orderURI = this.ordersBaseURI + '/' + encodeURIComponent(this.orderId);
  });...