Created
March 25, 2012 06:21
-
-
Save gr2m/2191748 to your computer and use it in GitHub Desktop.
Revisions
-
gr2m revised this gist
Mar 25, 2012 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
gr2m created this gist
Mar 25, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ jasmine.Matchers.prototype.toBePromise = -> this.actual.done && !this.actual.resolve jasmine.Matchers.prototype.toBeRejected = -> this.actual.isRejected() jasmine.Matchers.prototype.toBeResolved = -> this.actual.isResolved() jasmine.Matchers.prototype.toBeResolvedWith = -> expectedArgs = jasmine.util.argsToArray(arguments); unless this.actual.done throw new Error('Expected a promise, but got ' + jasmine.pp(this.actual) + '.'); done = jasmine.createSpy 'done' this.actual.done done this.message = -> if done.callCount == 0 return [ "Expected spy " + done.identity + " to have been resolved with " + jasmine.pp(expectedArgs) + " but it was never resolved.", "Expected spy " + done.identity + " not to have been resolved with " + jasmine.pp(expectedArgs) + " but it was." ]; else return [ "Expected spy " + done.identity + " to have been resolved with " + jasmine.pp(expectedArgs) + " but was resolved with " + jasmine.pp(done.argsForCall), "Expected spy " + done.identity + " not to have been resolved with " + jasmine.pp(expectedArgs) + " but was resolved with " + jasmine.pp(done.argsForCall) ]; return this.env.contains_(done.argsForCall, expectedArgs); jasmine.Matchers.prototype.toBeRejectedWith = -> expectedArgs = jasmine.util.argsToArray(arguments); unless this.actual.fail throw new Error('Expected a promise, but got ' + jasmine.pp(this.actual) + '.'); fail = jasmine.createSpy 'fail' this.actual.fail fail this.message = -> if fail.callCount == 0 return [ "Expected spy " + fail.identity + " to have been resolved with " + jasmine.pp(expectedArgs) + " but it was never resolved.", "Expected spy " + fail.identity + " not to have been resolved with " + jasmine.pp(expectedArgs) + " but it was." ]; else return [ "Expected spy " + fail.identity + " to have been resolved with " + jasmine.pp(expectedArgs) + " but was resolved with " + jasmine.pp(fail.argsForCall), "Expected spy " + fail.identity + " not to have been resolved with " + jasmine.pp(expectedArgs) + " but was resolved with " + jasmine.pp(fail.argsForCall) ]; return this.env.contains_(fail.argsForCall, expectedArgs); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ jasmine.Matchers.prototype.toBePromise = function() { return this.actual.done && !this.actual.resolve; }; jasmine.Matchers.prototype.toBeRejected = function() { return this.actual.isRejected(); }; jasmine.Matchers.prototype.toBeResolved = function() { return this.actual.isResolved(); }; jasmine.Matchers.prototype.toBeResolvedWith = function() { var done, expectedArgs; expectedArgs = jasmine.util.argsToArray(arguments); if (!this.actual.done) { throw new Error('Expected a promise, but got ' + jasmine.pp(this.actual) + '.'); } done = jasmine.createSpy('done'); this.actual.done(done); this.message = function() { if (done.callCount === 0) { return ["Expected spy " + done.identity + " to have been resolved with " + jasmine.pp(expectedArgs) + " but it was never resolved.", "Expected spy " + done.identity + " not to have been resolved with " + jasmine.pp(expectedArgs) + " but it was."]; } else { return ["Expected spy " + done.identity + " to have been resolved with " + jasmine.pp(expectedArgs) + " but was resolved with " + jasmine.pp(done.argsForCall), "Expected spy " + done.identity + " not to have been resolved with " + jasmine.pp(expectedArgs) + " but was resolved with " + jasmine.pp(done.argsForCall)]; } }; return this.env.contains_(done.argsForCall, expectedArgs); }; jasmine.Matchers.prototype.toBeRejectedWith = function() { var expectedArgs, fail; expectedArgs = jasmine.util.argsToArray(arguments); if (!this.actual.fail) { throw new Error('Expected a promise, but got ' + jasmine.pp(this.actual) + '.'); } fail = jasmine.createSpy('fail'); this.actual.fail(fail); this.message = function() { if (fail.callCount === 0) { return ["Expected spy " + fail.identity + " to have been resolved with " + jasmine.pp(expectedArgs) + " but it was never resolved.", "Expected spy " + fail.identity + " not to have been resolved with " + jasmine.pp(expectedArgs) + " but it was."]; } else { return ["Expected spy " + fail.identity + " to have been resolved with " + jasmine.pp(expectedArgs) + " but was resolved with " + jasmine.pp(fail.argsForCall), "Expected spy " + fail.identity + " not to have been resolved with " + jasmine.pp(expectedArgs) + " but was resolved with " + jasmine.pp(fail.argsForCall)]; } }; return this.env.contains_(fail.argsForCall, expectedArgs); };