# Testing Asyc Functions with chai-as-promised
Set up chai-as-promised:
const chai = require("chai");
const chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
const expect = chai.expect
General syntax:
it('Promise should be rejected with CustomError', function() {
return expect(asyncFn()).to.be.rejectedWith(CustomError)
})
it('Promise should pass', function() {
return expect(asyncFn()).to.be.fulfilled
})
// async-await alternative syntax
it('should work well with async/await', async function() {
await expect(asyncFn()).to.be.rejectedWith(Error);
})
Posted on: Sat, 23 Feb 2019 07:01:01 GMT