expect(promise).toHaveBeenResolved(done); expect(promise).toHaveBeenResolvedWith(done, expectation); expect(promise).toHaveBeenRejected(done); expect(promise).toHaveBeenRejectedWith(done, expectation);
Either you use in your browser jasmine test runner by adding it after the script-tag
Or when using jasmine-node you can simply install the matchers via:
npm install promise-matchers --save -dev
And make them available in your spec-file:
require'promise-matchers';describe;// or via requirejs (assuming your specs are within PROJECT_ROOT/test):require'../node_modules/promise-matchers/src/promise-matchers.js'describe;;
it'succeeds'var promise = foo;expectpromisetoHaveBeenResolveddone;;
it'fails'var promise = foo;expectpromisetoHaveBeenRejecteddone;;
it'succeeds with value of 3'var promise = foo;expectpromisetoHaveBeenResolvedWithdoneexpectresulttoBe3;;;
it'fails without saving'var save = spyOnBar 'save';var promise = foo;expectpromisetoHaveBeenRejectedWithdoneexpectsavenottoHaveBeenCalled;;;
- If a promise with an expectation of toHaveBeenResolved or toHaveBeenResolvedWith is rejected, the matcher fails with the message Expected promise to have been resolved.
- If a promise with an expectation of toHaveBeenRejected or toHaveBeenRejectedWith is resolved, the matcher fails with the message Expected promise to have been rejected.
- If an expectation passed to toHaveBeenResolvedWith or toHaveBeenRejectedWith fails, the matcher fails with that expectation's failure message.
- If an expectation passed to toHaveBeenResolvedWith or toHaveBeenRejectedWith throws an exception, the matcher fails with the exception text.
- These matchers will not behave properly with not.