Skip to content

Instantly share code, notes, and snippets.

@zhentian-wan
Created November 11, 2016 13:13
Show Gist options
  • Save zhentian-wan/601e15e702ee6b1f0fccb718ede21116 to your computer and use it in GitHub Desktop.
Save zhentian-wan/601e15e702ee6b1f0fccb718ede21116 to your computer and use it in GitHub Desktop.
Testing promise with mocha & chai as promised
const chai = require('chai');
const expect = chai.expect;
const chaiAsPromised = require('chai-as-promised');
const index = require('../index.js');
chai.use(chaiAsPromised);
describe('Function foo', () => {
it('should accpet anything but one', () => {
const promise = index.foo(0);
return expect(promise).to.eventually.equal(0);
});
it('should throw error is apply one', () => {
const promise = index.foo(1);
// return expect(promise).to.be.rejected;
return expect(promise).to.be.rejectedWith('Found an error');
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment