Custom matchers for use with Jasmine 2.0 and Angular promises.
bower install jasmine-promise-matchers --save
Tests often require simple assertions about Promise resolution/rejection. This could be accomplished by spying on the Promise object or by chaining on another Promise (complete with expects statements)- but this is a lot of work. The following matchers allow basic assertions to be made about Promises via a brief expectation.
Don't forget to trigger the digest loop after using one of these matchers!
Verifies that a Promise is rejected before the end of the test.
expect(promise).toBeRejected();
Verifies that a Promise is rejected with the specified parameter before the end of the test.
expect(promise).toBeRejectedWith('something');
Verifies that a Promise is resolved before the end of the test.
expect(promise).toBeResolved();
Verifies that a Promise is resolved with the specified parameter before the end of the test.
expect(promise).toBeResolvedWith('something');