HTML and CSS Reference
In-Depth Information
Listing 14.34 Expecting addMessage not to require a callback
/* ... */
/* ... */
testCase(exports, "chatRoom.addMessage", {
/* ... */
"should not require a callback": function (test) {
test.noException(function () {;
Once again we load the custom bind implementation to bind the anonymous
callback to test.noException . To pass the test we need to check that the
callback is callable before calling it, as Listing 14.35 shows.
Listing 14.35 Verifying that callback is callable before calling it
addMessage: function (user, message, callback) {
var err = null;
if (!user) { err = new TypeError("user is null"); }
if (!message) { err = new TypeError("message is null"); }
if (typeof callback == "function") {
} Successfully Adding Messages
We won't be able to verify that messages are actually stored until we have a way
to retrieve them, but we should get some indication on whether or not adding the
message was successful. To do this we'll expect the method to call the callback with
a message object. The object should contain the data we passed in along with an id.
The test can be seen in Listing 14.36.
Search WWH ::

Custom Search