0

I'm using Mocha and Should.js to test a promise that I am expecting to generate an error.

Because it is a promise, I don't believe I can simply use should.throwError(). This just means that I would like to fail the unit test in the .catch block of the promise.

How do I explicitly fail a unit test using without using some sort of stupid hack like 1.should.equal(2)?

Example Code (Which does not work)

it('should throw an error.', function(done) {
  myPromiseGenerator().then(function() {
    should.fail();
    done();
  }).catch(function(e) {
    done();
  })
}
slifty
  • 13,062
  • 13
  • 71
  • 109

1 Answers1

2

Pass the error to the done function.

it('should throw an error.', function(done) {
  myPromiseGenerator().then(function() {
    done(new Error("should not succeed"));
  }).catch(function(e) {
    done();
  })
}
Transcendence
  • 2,616
  • 3
  • 21
  • 31