toBeRejectedWithError can expect the error to be Error, not just a subtype
This commit is contained in:
@@ -294,15 +294,12 @@ describe('Matchers (Integration)', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('toBeRejectedWithError', function() {
|
describe('toBeRejectedWithError', function() {
|
||||||
function MyCustomError() {}
|
|
||||||
MyCustomError.prototype = new Error();
|
|
||||||
|
|
||||||
verifyPassesAsync(function(env) {
|
verifyPassesAsync(function(env) {
|
||||||
return env.expectAsync(Promise.reject(new MyCustomError())).toBeRejectedWithError(MyCustomError);
|
return env.expectAsync(Promise.reject(new Error())).toBeRejectedWithError(Error);
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyFailsAsync(function(env) {
|
verifyFailsAsync(function(env) {
|
||||||
return env.expectAsync(Promise.resolve()).toBeRejectedWithError(MyCustomError);
|
return env.expectAsync(Promise.resolve()).toBeRejectedWithError(Error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,21 @@ describe('#toBeRejectedWithError', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('passes when Error matches and is exactly Error', function() {
|
||||||
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
|
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
|
||||||
|
actual = Promise.reject(new Error());
|
||||||
|
|
||||||
|
return matcher.compare(actual, Error).then(function (result) {
|
||||||
|
expect(result).toEqual(jasmine.objectContaining({
|
||||||
|
pass: true,
|
||||||
|
message: 'Expected a promise not to be rejected with Error, but it was.'
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
it('passes when Error message matches a string', function () {
|
it('passes when Error message matches a string', function () {
|
||||||
jasmine.getEnv().requirePromises();
|
jasmine.getEnv().requirePromises();
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ getJasmineRequireObj().toBeRejectedWithError = function(j$) {
|
|||||||
function getExpectedFromArgs(arg1, arg2) {
|
function getExpectedFromArgs(arg1, arg2) {
|
||||||
var error, message;
|
var error, message;
|
||||||
|
|
||||||
if (typeof arg1 === 'function' && j$.isError_(arg1.prototype)) {
|
if (isErrorConstructor(arg1)) {
|
||||||
error = arg1;
|
error = arg1;
|
||||||
message = arg2;
|
message = arg2;
|
||||||
} else {
|
} else {
|
||||||
@@ -90,4 +90,8 @@ getJasmineRequireObj().toBeRejectedWithError = function(j$) {
|
|||||||
printValue: j$.fnNameFor(error) + (typeof message === 'undefined' ? '' : ': ' + j$.pp(message))
|
printValue: j$.fnNameFor(error) + (typeof message === 'undefined' ? '' : ': ' + j$.pp(message))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isErrorConstructor(value) {
|
||||||
|
return typeof value === 'function' && (value === Error || j$.isError_(value.prototype));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user