Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
test(modal): fix custom matchers
Browse files Browse the repository at this point in the history
- Trigger a test failure if resolved on rejected promise and rejected on resolved promise
- Trigger a test failure if neither resolved or rejected when expected resolved/rejected promise

Closes #6195
  • Loading branch information
wesleycho committed Aug 22, 2016
1 parent 515bcf2 commit 6734908
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ describe('$uibModal', function() {
toBeResolvedWith: function(util, customEqualityTesters) {
return {
compare: function(promise, expected) {
var called = false;
promise.then(function(result) {
expect(result).toEqual(expected);

Expand All @@ -169,10 +170,18 @@ describe('$uibModal', function() {
} else {
result.message = 'Expected "' + angular.mock.dump(result) + '" to be resolved with "' + expected + '".';
}
}, function(result) {
fail('Expected "' + angular.mock.dump(result) + '" to be resolved with "' + expected + '".');
})['finally'](function() {
called = true;
});

$rootScope.$digest();

if (!called) {
fail('Expected "' + angular.mock.dump(result) + '" to be resolved with "' + expected + '".');
}

return {pass: true};
}
};
Expand All @@ -181,9 +190,10 @@ describe('$uibModal', function() {
return {
compare: function(promise, expected) {
var result = {};
var called = false;

promise.then(function() {

promise.then(function(result) {
fail('Expected "' + angular.mock.dump(result) + '" to be rejected with "' + expected + '".');
}, function(result) {
expect(result).toEqual(expected);

Expand All @@ -192,10 +202,16 @@ describe('$uibModal', function() {
} else {
result.message = 'Expected "' + angular.mock.dump(result) + '" to be rejected with "' + expected + '".';
}
})['finally'](function() {
called = true;
});

$rootScope.$digest();

if (!called) {
fail('Expected "' + angular.mock.dump(result) + '" to be rejected with "' + expected + '".');
}

return {pass: true};
}
};
Expand Down

0 comments on commit 6734908

Please sign in to comment.