Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yilazius opened this issue Apr 10, 2017 · 1 comment
Open

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

yilazius opened this issue Apr 10, 2017 · 1 comment

Comments

@yilazius
Copy link

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

@wmzy
Copy link

wmzy commented Dec 6, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants