To test the the exception in a rejected promise could be a little bit painful.
And Mocha is Promise-friendly, which means it fails the test if exception is not caught.
So as a result, here is a simple code example to explain how it is being done:
|
|
Update: A Chai Plugin can mitigate the pain
|
|
Update 2: With async, it can be converted into normal test12345it('should throw session-expired exception', () => { return expect(async () => await new Session().generateId().bindUserFromRedis()) .to.throw .and.that.have.property('errorName', 'session-expired')})