Fix failure messages for toBeRejectedWithError matcher

This commit is contained in:
Alexey Prokhorov
2019-05-03 09:37:11 +04:00
parent 35968e4a60
commit 8ab46566ac
2 changed files with 56 additions and 15 deletions

View File

@@ -6,7 +6,10 @@ describe('#toBeRejectedWithError', function () {
actual = Promise.reject(new TypeError('foo'));
return matcher.compare(actual, TypeError).then(function (result) {
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
expect(result).toEqual(jasmine.objectContaining({
pass: true,
message: 'Expected a promise not to be rejected with TypeError, but it was.'
}));
});
});
@@ -17,7 +20,10 @@ describe('#toBeRejectedWithError', function () {
actual = Promise.reject(new TypeError('foo'));
return matcher.compare(actual, TypeError, 'foo').then(function (result) {
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
expect(result).toEqual(jasmine.objectContaining({
pass: true,
message: 'Expected a promise not to be rejected with TypeError: \'foo\', but it was.'
}));
});
});
@@ -28,7 +34,10 @@ describe('#toBeRejectedWithError', function () {
actual = Promise.reject(new Error('foo'));
return matcher.compare(actual, 'foo').then(function (result) {
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
expect(result).toEqual(jasmine.objectContaining({
pass: true,
message: 'Expected a promise not to be rejected with Error: \'foo\', but it was.'
}));
});
});
@@ -39,7 +48,10 @@ describe('#toBeRejectedWithError', function () {
actual = Promise.reject(new Error('foo'));
return matcher.compare(actual, /foo/).then(function (result) {
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
expect(result).toEqual(jasmine.objectContaining({
pass: true,
message: 'Expected a promise not to be rejected with Error: /foo/, but it was.'
}));
});
});
@@ -50,7 +62,24 @@ describe('#toBeRejectedWithError', function () {
actual = Promise.reject(new Error());
return matcher.compare(actual, '').then(function (result) {
expect(result).toEqual(jasmine.objectContaining({ pass: true }));
expect(result).toEqual(jasmine.objectContaining({
pass: true,
message: 'Expected a promise not to be rejected with Error: \'\', but it was.'
}));
});
});
it('passes when no arguments', function () {
jasmine.getEnv().requirePromises();
var matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(jasmineUnderTest.matchersUtil),
actual = Promise.reject(new Error());
return matcher.compare(actual, void 0).then(function (result) {
expect(result).toEqual(jasmine.objectContaining({
pass: true,
message: 'Expected a promise not to be rejected with Error, but it was.'
}));
});
});
@@ -61,7 +90,10 @@ describe('#toBeRejectedWithError', function () {
actual = Promise.resolve(new Error('foo'));
return matcher.compare(actual, 'foo').then(function (result) {
expect(result).toEqual(jasmine.objectContaining({ pass: false }));
expect(result).toEqual(jasmine.objectContaining({
pass: false,
message: 'Expected a promise to be rejected but it was resolved.'
}));
});
});
@@ -72,7 +104,10 @@ describe('#toBeRejectedWithError', function () {
actual = Promise.reject('foo');
return matcher.compare(actual, 'foo').then(function (result) {
expect(result).toEqual(jasmine.objectContaining({ pass: false }));
expect(result).toEqual(jasmine.objectContaining({
pass: false,
message: 'Expected a promise to be rejected with Error: \'foo\' but it was rejected with \'foo\'.'
}));
});
});
@@ -83,7 +118,10 @@ describe('#toBeRejectedWithError', function () {
actual = Promise.reject(new Error('foo'));
return matcher.compare(actual, TypeError, 'foo').then(function (result) {
expect(result).toEqual(jasmine.objectContaining({ pass: false }));
expect(result).toEqual(jasmine.objectContaining({
pass: false,
message: 'Expected a promise to be rejected with TypeError: \'foo\' but it was rejected with type Error.'
}));
});
});
@@ -94,7 +132,10 @@ describe('#toBeRejectedWithError', function () {
actual = Promise.reject(new Error('foo'));
return matcher.compare(actual, 'bar').then(function (result) {
expect(result).toEqual(jasmine.objectContaining({ pass: false }));
expect(result).toEqual(jasmine.objectContaining({
pass: false,
message: 'Expected a promise to be rejected with Error: \'bar\' but it was rejected with Error: foo.'
}));
});
});
});