HTML and CSS Reference
In-Depth Information
Listing 14.75 Expecting an object passed to respond
function controllerSetUp() {
var req = this.req = new EventEmitter();
req.headers = { "x-access-token": "" };
/* ... */
var add = this.addMessagePromise = new Promise();
var wait = this.waitForMessagesPromise = new Promise();
this.controller.chatRoom = {
addMessage: stub(add),
waitForMessagesSince: stub(wait)
};
/* ... */
}
/* ... */
testCase(exports, "chatRoomController.respond", {
/* ... */
"should respond with formatted data": function (test) {
this.controller.respond = stub();
var messages = [{ user: "cjno", message: "hi" }];
this.waitForMessagesPromise.resolve(messages);
this.controller.get();
process.nextTick(function () {
test.ok(this.controller.respond.called);
var args = this.controller.respond.args;
test.same(args[0], 201);
test.same(args[1].message, messages);
test.done();
}.bind(this));
}
});
This test is a bit of a mouthful, and to make it slightly easier to digest, the setUp
method was augmented. All the tests so far have stubbed waitForMessagesS-
ince , and all of them require the headers to be set. Pulling these out makes it easier
to focus on what the test in question is trying to achieve.
 
Search WWH ::




Custom Search