Skip to content

Instantly share code, notes, and snippets.

@deckar01
Last active March 7, 2016 22:02
Show Gist options
  • Save deckar01/e9ec4af655eaeb742781 to your computer and use it in GitHub Desktop.
Save deckar01/e9ec4af655eaeb742781 to your computer and use it in GitHub Desktop.
Working replacement of promise-matchers for jasmine 2
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