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:
var resolvedValue;
promise.then(
function(value) {
resolvedValue = value;
});
jasmine.clock().tick(1);
expect(resolvedValue).toBe('something');
Using the matchers provided by this library, your tests could instead look like this:
expect(promise).toBeResolvedWith('something');
Initializing the library
To use it, just install the library before your tests begin:
beforeEach(function() {
// `true` automatically ticks the Jasmine mock-clock for you after each assert.
// `false` leaves the clock management up to you.
// I recommend `true` unless your test involves other timing concerns.
JasminePromisMatchers.install(true);
});
And uninstall it once your tests are over:
afterEach(function() {
JasminePromisMatchers.uninstall();
});
Now you're ready to start testing!
Using the matchers
This library includes a couple of matchers, shown below.
toBeRejected
Verify that a Promise is rejected!
expect(promise).toBeRejected();
toBeRejectedWith
Verify that a Promise is rejected with a specific value:
expect(promise).toBeRejectedWith('something');
toBeResolved
Verify that a Promise is resolved!
expect(promise).toBeResolved();
toBeResolvedWith
Verify that a Promise is resolved with a specific value:
expect(promise).toBeResolvedWith('something');
Questions? Suggestions?
Open an issue or toss up a pull request if you'd like to see anything added to this library!