HTML and CSS Reference
In-Depth Information
room.addMessage(user, "msg", function (e, first) {
room.addMessage(user, "msg2", function (e, second) {
room.getMessagesSince(first.id, function (e, msgs) {
test.isArray(msgs);
test.same(msgs, [second]);
test.done();
});
});
});
}
});
The test fails in the face of a missing getMessagesSince . Listing 14.41 adds
an empty method that simply calls the callback without arguments.
Listing 14.41 Adding getMessagesSince
var chatRoom = {
addMessage: function (user, message, callback) { /* ... */ },
getMessagesSince: function (id, callback) {
callback();
}
};
Because addMessage isn't really storing the messages anywhere, there's no
way for getMessagesSince to retrieve it. In other words, to pass this test we
need to fix addMessage , like Listing 14.42 shows.
Listing 14.42 Actually adding messages
addMessage: function (user, message, callback) {
/* ... */
if (!err) {
if (!this.messages) {
this.messages = [];
}
var id = this.messages.length + 1;
data={id:id,user: user, message: message };
this.messages.push(data);
}
/* ... */
}
 
Search WWH ::




Custom Search