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

fix(modal): should not throw an exception when a modal isn't on the stack #1972

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,17 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
};

$modalStack.close = function (modalInstance, result) {
var modalWindow = openedWindows.get(modalInstance).value;
var modalWindow = openedWindows.get(modalInstance);
if (modalWindow) {
modalWindow.deferred.resolve(result);
modalWindow.value.deferred.resolve(result);
removeModalWindow(modalInstance);
}
};

$modalStack.dismiss = function (modalInstance, reason) {
var modalWindow = openedWindows.get(modalInstance).value;
var modalWindow = openedWindows.get(modalInstance);
if (modalWindow) {
modalWindow.deferred.reject(reason);
modalWindow.value.deferred.reject(reason);
removeModalWindow(modalInstance);
}
};
Expand Down
31 changes: 31 additions & 0 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe('$modal', function () {

function close(modal, result) {
modal.close(result);
$timeout.flush();
$rootScope.$digest();
}

Expand Down Expand Up @@ -135,6 +136,36 @@ describe('$modal', function () {
expect($document).not.toHaveBackdrop();
});

it('should not throw an exception on a second dismiss', function () {

var modal = open({template: '<div>Content</div>'});

expect($document).toHaveModalsOpen(1);
expect($document).toHaveModalOpenWithContent('Content', 'div');
expect($document).toHaveBackdrop();

dismiss(modal, 'closing in test');

expect($document).toHaveModalsOpen(0);

dismiss(modal, 'closing in test');
});

it('should not throw an exception on a second close', function () {

var modal = open({template: '<div>Content</div>'});

expect($document).toHaveModalsOpen(1);
expect($document).toHaveModalOpenWithContent('Content', 'div');
expect($document).toHaveBackdrop();

close(modal, 'closing in test');

expect($document).toHaveModalsOpen(0);

close(modal, 'closing in test');
});

it('should open a modal from templateUrl', function () {

$templateCache.put('content.html', '<div>URL Content</div>');
Expand Down