https://github.com/bkeepers/expect-promise
an extension to expect for testing promises
https://github.com/bkeepers/expect-promise
Last synced: 13 days ago
JSON representation
an extension to expect for testing promises
- Host: GitHub
- URL: https://github.com/bkeepers/expect-promise
- Owner: bkeepers
- Created: 2016-11-27T15:13:30.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-11-27T15:18:49.000Z (over 9 years ago)
- Last Synced: 2025-01-18T06:25:03.691Z (over 1 year ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# expect-promise
an extension to [expect](https://github.com/mjackson/expect) for testing promises.
## Installation
$ npm install --save-dev expect-promise
## API
- `expect(promise).toBeAPromise()`
- `expect(promise).toHaveBeenResolved(done)`
- `expect(promise).toHaveBeenRejected(done)`
## Usage
```js
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](https://mochajs.org/#asynchronous-code).