HTML and CSS Reference
In-Depth Information
The test passes, and we can move on to checking the message. The test in
Listing 14.31 expects addMessage to require a message.
Listing 14.31 addMessage should require message
"should require message": function (test) {
var room = Object.create(chatRoom);
room.addMessage("cjno", null, function (err) {
test.inherits(err, TypeError);
The test introduces some duplication that we'll deal with shortly. First,
Listing 14.32 makes the check that passes it.
Listing 14.32 Checking the message
addMessage: function (user, message, callback) {
/* ... */
if (!message) {
callback(new TypeError("message is null"));
All the tests pass. Listing 14.33 adds a setUp method to remove the duplicated
creation of the chatRoom object.
Listing 14.33 Adding a setUp method
testCase(exports, "chatRoom.addMessage", {
setUp: function () { = Object.create(chatRoom);
/* ... */
As we decided previously, the callback should be optional, so Listing 14.34 adds
a test that expects the method not to fail when the callback is missing.
Search WWH ::

Custom Search