Wednesday, 10 May 2017

What is the difference between calling chai-as-promised with or without a notify method?

I'm using chai and chai-as-promised to test some asynchronous JS code.

I just want to check that a function returning a promise will eventually return an Array and wrote the 2 following tests:

A:

it('should return an array', () => {
    foo.bar().should.eventually.to.be.a('array')
})

B:

it('should return an array', (done) => {
    foo.bar().should.eventually.to.be.a('array').notify(done)
})

Both are passing OK, but only the B option actually runs the full code included in my bar() function (ie displaying the console.log() message from the code below). Am I doing something wrong? Why is that so?

bar() {
    return myPromise()
    .then((result) => {
      console.log('Doing stuff')
      return result.body.Data
    })
    .catch((e) => {
      console.err(e)
    })
  }



via Dirty Henry

No comments:

Post a Comment