HTML and CSS Reference
In-Depth Information
At this point the property descriptors don't provide anything we have a doc-
umented need for (i.e., the ability to override default property attribute values),
so we'll avoid the added indentation and stick with the simple assignments in
Listing 14.55.
Next up, we make sure that addMessage emits an event. Listing 14.57 shows
the test.
Listing 14.57 Expecting addMessage to emit a “message” event
testCase(exports, "chatRoom.addMessage", {
/* ... */
"should emit 'message' event": function (test) {
var message;
this.room.addListener("message", function (m) {
message = m;
});
this.room.addMessage("cjno", "msg").then(function (m) {
test.same(m, message);
test.done();
});
}
});
To pass this test we need to place a call to emit right before we resolve the
promise, as seen in Listing 14.58.
Listing 14.58 Emitting a message event
chatRoom.addMessage= function (user, message, callback) {
var promise = new Promise()
process.nextTick(function () {
/* ... */
if (!err) {
/* ... */
this.emit("message", data);
promise.resolve(data);
} else {
promise.reject(err, true);
}
 
Search WWH ::




Custom Search