Last active
March 7, 2016 22:02
-
-
Save deckar01/e9ec4af655eaeb742781 to your computer and use it in GitHub Desktop.
Working replacement of promise-matchers for jasmine 2
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 characters
beforeEach(function () { | |
jasmine.addMatchers({ | |
toHaveBeenResolved: function() { | |
return { | |
compare: function(promise) { | |
promise | |
.thenCatch(function() { | |
expect('promise').toBe('resolved'); | |
}); | |
return { pass: true }; | |
} | |
}; | |
}, | |
toHaveBeenResolvedWith: function() { | |
return { | |
compare: function(promise, expected) { | |
promise | |
.then(function(actual) { | |
expect(actual).toBe(expected); | |
}) | |
.thenCatch(function() { | |
expect('promise').toBe('resolved'); | |
}); | |
return { pass: true }; | |
} | |
}; | |
}, | |
toHaveBeenRejected: function() { | |
return { | |
compare: function(promise) { | |
promise | |
.then(function() { | |
expect('promise').toBe('rejected'); | |
}) | |
.thenCatch(function() {}); | |
return { pass: true }; | |
} | |
}; | |
}, | |
toHaveBeenRejectedWith: function() { | |
return { | |
compare: function(promise, expected) { | |
promise | |
.then(function() { | |
expect('promise').toBe('rejected'); | |
}) | |
.thenCatch(function(actual) { | |
expect(actual).toBe(expected); | |
}); | |
return { pass: true }; | |
} | |
}; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment