Package Exports
- jasmine-es6-promise-matchers
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jasmine-es6-promise-matchers) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Jasmine Promise Matchers
Custom matchers for testing ES6 Promises with Jasmine 2.x.
This library is compatible with the ES6Promise polyfill library if the current browser does not support ES6 Promises. (This means it will work with Phantom JS.)
Installing
You can install with either NPM or Bower like so:
npm install jasmine-es6-promise-matchers
bower install jasmine-es6-promise-matchers
Overview
Testing promises should be simple but it's normally a bit of a hassle. Your tests probably look something like this:
function(done) {
promise.then(
function(value) {
expect(value).toBe('something');
done();
},
done.fail);
Using the matchers provided by this library your tests could instead look like this:
function(done) {
expect(promise).toBeResolvedWith('something', done);
}
Initializing the library
To use it, just install the library before your tests begin:
beforeEach(JasminePromiseMatchers.install);
And uninstall it once your tests are over:
afterEach(JasminePromiseMatchers.uninstall);
Now you're ready to start testing!
Using the matchers
This library includes a couple of matchers, shown below.
toBeRejected(done:Function)
Verify that a Promise is (or will be) rejected.
expect(promise).toBeRejected(done);
toBeRejectedWith(data:*, done:Function)
Verify that a Promise is rejected with a specific value.
expect(promise).toBeRejectedWith('something', done);
// Asymmetric matching is also supported for objects:
var partialMatch = jasmine.objectContaining({partial: 'match'});
expect(promise).toBeRejectedWith(partialMatch, done);
toBeResolved(done:Function)
Verify that a Promise is resolved.
expect(promise).toBeResolved(done);
toBeResolvedWith(data:*, done:Function)
Verify that a Promise is resolved with a specific value.
expect(promise).toBeResolvedWith('something', done);
// Asymmetric matching is also supported for objects:
var partialMatch = jasmine.objectContaining({partial: 'match'});
expect(promise).toBeResolvedWith(partialMatch, done);
Questions? Suggestions?
Open an issue or toss up a pull request if you'd like to see anything added to this library!