HTML and CSS Reference
In-Depth Information
Listing 14.36 Expecting addMessage to pass the created message
"should call callback with new object": function (test) {
var txt = "Some message";"cjno", txt, function (err, msg) {
test.equals(msg.message, txt);
test.equals(msg.user, "cjno");
Listing 14.37 shows an attempt at passing the test. It calls the callback with an
object and cheats the id by hard-coding it to 1.
Listing 14.37 Passing the object to the callback
addMessage: function (user, message, callback) {
/* ... */
var data;
if (!err) {
data={id:1,user: user, message: message };
if (typeof callback == "function") {
callback(err, data);
With this in place, the tests are back to green. Next up, the id should be unique
for every message. Listing 14.38 shows the test.
Listing 14.38 Expecting unique message ids
"should assign unique ids to messages": function (test) {
var user = "cjno";, "a", function (err, msg1) {, "b", function (err, msg2) {
Search WWH ::

Custom Search