From 6734908108e0dee99e6a8ee1244cdcf7a5883436 Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Sun, 21 Aug 2016 12:15:13 -0700 Subject: [PATCH] test(modal): fix custom matchers - 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 --- src/modal/test/modal.spec.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index c11e15804a..98d3d258c9 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -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); @@ -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}; } }; @@ -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); @@ -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}; } };