HTML and CSS Reference
In-Depth Information
/* ... */
}
testCase(exports, "chatRoomController.post", {
/* ... */
"should write status header": function (test) {
var data = { data: { user: "cjno", message: "hi" } };
this.controller.post();
this.sendRequest(data);
test.ok(this.res.writeHead.called);
test.equals(this.res.writeHead.args[0], 201);
test.done();
}
});
Listing 14.22 faces the challenge and makes the actual call to writeHead .
Listing 14.22 Setting the response code
post: function () {
/* ... */
this.request.addListener("end", function () {
var data = JSON.parse(decodeURI(body)).data;
this.chatRoom.addMessage(data.user, data.message);
this.response.writeHead(201);
}.bind(this));
}
14.2.5.2 Closing the Connection
Once the headers have been written, we should make sure the connection is closed.
Listing 14.23 shows the test.
Listing 14.23 Expecting the response to be closed
function controllerSetUp() {
/* ... */
var res = this.res = {
writeHead: stub(),
end: stub()
};
/* ... */
};
 
Search WWH ::




Custom Search