hubot-test-helper icon indicating copy to clipboard operation
hubot-test-helper copied to clipboard

Message send in Timeout aren't tracked in room.messages

Open yilazius opened this issue 7 years ago • 1 comments

I do have a function registered which goes like

  robot.respond /hello/i , (msg) ->
    setTimeout () ->
        console.log "Reached timeout"
        msg.send "Hello World!"
    , 1

and I'm expecting this test to succeed:

    it 'should display hello world', ->
      room.user.say('dex', '@hubot hello').then =>
            clock.tick(2)
            console.log "Reached assertion"
            expect(room.messages).to.eql [
                ['dex',   '@hubot hello']        
                ['hubot', 'Hello World!']
            ]

Unfortunately room.messages is missing the response by hubot. Note: clock.tick(2) is using sion to mock the system time. To be sure that sion works correctly I added two log statements. Both of them are executed in my expected order:

Reached timeout
Reached assertion

Help in this matter would be highly appreciated!

Best Sebastian

yilazius avatar Apr 10 '17 18:04 yilazius

@yilazius I also encountered this problem.I solved it like below:

it('reply with related', function () {
    return this.room.user.say('alice', '@hubot hello')
      .then(() => new Promise((res) => {
        const reply = this.room.reply.bind(this.room);
        this.room.reply = (...arg) => {
          reply(...arg);
          res();
        };
      }))
      .then(() => {
        // todo assert
      });
  });

I think the hubot-test-helper should give an easier way for async test.

wmzy avatar Dec 06 '17 08:12 wmzy