HTML and CSS Reference
In-Depth Information
/* ... */
"should write status header when addMessage resolves":
function (test) {
var data = { data: { user: "cjno", message: "hi" } };
this.controller.post();
this.sendRequest(data);
this.addMessagePromise.resolve({});
process.nextTick(function () {
test.ok(this.res.writeHead.called);
test.equals(this.res.writeHead.args[0], 201);
test.done();
}.bind(this));
},
/* ... */
});
Delaying the verification doesn't affect the test very much, so the fact that
it still passes only tells us none of the new setup code is broken. We can apply
the same update to the following test, which expects the connection to be closed.
Listing 14.66 shows the updated test.
Listing 14.66 Expecting post not to close connection immediately
"should close connection when addMessage resolves":
function (test) {
var data = { data: { user: "cjno", message: "hi" } };
this.controller.post();
this.sendRequest(data);
this.addMessagePromise.resolve({});
process.nextTick(function () {
test.ok(this.res.end.called);
test.done();
}.bind(this));
}
Listing 14.67 shows a new test, which contradicts the two tests the way they
were previously written. This test specifically expects the action not to respond
before addMessage has resolved.
 
Search WWH ::




Custom Search