gratifyguy / botkit-mock

Write tests for Botkit.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Promise bug in sample code

alecl opened this issue · comments

If I run it as written I get the following:

Error: Resolution method is overspecified. Specify a callback or return a Promise; not both.

    it('should return `help message` if user types `help`', (done)=>{
        var self = this;
        return self.controller.usersInput([{
                first:true,
                user: self.slackId,
                messages:[{text: 'help', isAssertion:true}]
            }]).then((text)=>{
                assert.equal(text, 'help message')
                done()
            })
    });

If I remove the done and just return the promise it's fine. Also, suggest adding a catch and return rejection or you miss out on important errors

    it('should return `help message` if user types `help`', ()=>{
        var self = this;
        return self.controller.usersInput([{
                first:true,
                user: self.slackId,
                messages:[{text: 'help', isAssertion:true}]
      }])
        .catch((err) => {
          return Promise.reject(err);
        }).then((text) => {
          assert.equal(text, 'help message')
        })
    });

Fixed in PR #16

yeah, make sense. ty