Skip to content

bkeepers/expect-promise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

expect-promise

an extension to expect for testing promises.

Installation

$ npm install --save-dev expect-promise

API

  • expect(promise).toBeAPromise()
  • expect(promise).toHaveBeenResolved(done)
  • expect(promise).toHaveBeenRejected(done)

Usage

const expect = require('expect');
const expectPromise = require('expect-promise');

expect.extend(expectPromise);

describe('expect-promise', () => {
  it('passes when promise was resolved', done => {
    expect(Promise.resolve()).toHaveBeenResolved(done);
  });

  it('fails when resolved promise was expected to be rejected', done => {
    expect(Promise.resolve()).toHaveBeenRejected(done);
  });
});

Note! Since Promises are an asynchronous feature, toHaveBeenResolved and toHaveBeenRejected expect the done callback that is passed as an argument to it. This callback will be called with an error when the promise is resolved or rejected, which will pass or fail the test for asynchronous code in mocha.

About

an extension to expect for testing promises

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published