Skip to content

Commit

Permalink
waitForMessagesSince has new message resolve waiting
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan committed Apr 27, 2012
1 parent cf59db5 commit 8e5afa4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion chapp/chat_room.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ chatRoom.waitForMessagesSince = function(id){
if(messages.length > 0){
promise.resolve(messages);
} else {
this.addListener('message', function() {});
this.addListener('message', function(message) {
promise.resolve([message]);
});
}
}.bind(this));

Expand Down
16 changes: 16 additions & 0 deletions test/chat_room_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,20 @@ suite('chatRoom.waitForMessagesSince', function(){
done();
}.bind(this));
});
test('new message should resolve waiting', function(done){
var user = 'cjno',
msg = 'Are you waiting for this?';

this.room.waitForMessagesSince(0).then(function(msgs){
assert.isArray(msgs);
assert.equal(msgs.length, 1);
assert.equal(msgs[0].user, user);
assert.equal(msgs[0].message, msg);
done();
});

process.nextTick(function(){
this.room.addMessage(user, msg);
}.bind(this));
});
});

0 comments on commit 8e5afa4

Please sign in to comment.