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

Commit 83c69c3

Browse files
committed
chore: ensure tests are gc'd
- Ensure event listeners globally on service instantiation are garbage collected properly
1 parent 75b8e5a commit 83c69c3

File tree

8 files changed

+40
-8
lines changed

8 files changed

+40
-8
lines changed

src/modal/modal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
331331
}
332332
}
333333

334-
$document.bind('keydown', function(evt) {
334+
$document.on('keydown', function(evt) {
335335
if (evt.isDefaultPrevented()) {
336336
return evt;
337337
}

src/modal/test/modal.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ describe('$uibModal', function () {
154154
body.find('div.modal').remove();
155155
body.find('div.modal-backdrop').remove();
156156
body.removeClass('modal-open');
157+
$document.off('keydown');
157158
});
158159

159160
function triggerKeyDown(element, keyCode, shiftKey) {

src/popover/test/popover-html.spec.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ describe('popover', function() {
1111
// load the template
1212
beforeEach(module('uib/template/popover/popover-html.html'));
1313

14-
beforeEach(inject(function($rootScope, $compile, $sce) {
14+
beforeEach(inject(function($rootScope, $compile, $sce, _$document_) {
15+
$document = _$document_;
1516
elmBody = angular.element(
1617
'<div><span uib-popover-html="template">Selector Text</span></div>'
1718
);
@@ -25,6 +26,10 @@ describe('popover', function() {
2526
tooltipScope = elmScope.$$childTail;
2627
}));
2728

29+
afterEach(function() {
30+
$document.off('keypress');
31+
});
32+
2833
it('should not be open initially', inject(function() {
2934
expect(tooltipScope.isOpen).toBe(false);
3035

src/popover/test/popover-template.spec.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ describe('popover template', function() {
33
elmBody,
44
scope,
55
elmScope,
6-
tooltipScope;
6+
tooltipScope,
7+
$document;
78

89
// load the popover code
910
beforeEach(module('ui.bootstrap.popover'));
@@ -16,7 +17,8 @@ describe('popover template', function() {
1617
$templateCache.put('myUrl', [200, '<span>{{ myTemplateText }}</span>', {}]);
1718
}));
1819

19-
beforeEach(inject(function($rootScope, $compile) {
20+
beforeEach(inject(function($rootScope, $compile, _$document_) {
21+
$document = _$document_;
2022
elmBody = angular.element(
2123
'<div><span uib-popover-template="templateUrl">Selector Text</span></div>'
2224
);
@@ -31,6 +33,10 @@ describe('popover template', function() {
3133
tooltipScope = elmScope.$$childTail;
3234
}));
3335

36+
afterEach(function() {
37+
$document.off('keypress');
38+
});
39+
3440
it('should open on click', inject(function() {
3541
elm.trigger('click');
3642
tooltipScope.$digest();

src/popover/test/popover.spec.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ describe('popover', function() {
33
elmBody,
44
scope,
55
elmScope,
6-
tooltipScope;
6+
tooltipScope,
7+
$document;
78

89
// load the popover code
910
beforeEach(module('ui.bootstrap.popover'));
1011

1112
// load the template
1213
beforeEach(module('uib/template/popover/popover.html'));
1314

14-
beforeEach(inject(function($rootScope, $compile) {
15+
beforeEach(inject(function($rootScope, $compile, _$document_) {
16+
$document = _$document_;
1517
elmBody = angular.element(
1618
'<div><span uib-popover="popover text">Selector Text</span></div>'
1719
);
@@ -24,6 +26,10 @@ describe('popover', function() {
2426
tooltipScope = elmScope.$$childTail;
2527
}));
2628

29+
afterEach(function() {
30+
$document.off('keypress');
31+
});
32+
2733
it('should not be open initially', inject(function() {
2834
expect(tooltipScope.isOpen).toBe(false);
2935

src/tooltip/test/tooltip-template.spec.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ describe('tooltip template', function() {
33
elmBody,
44
scope,
55
elmScope,
6-
tooltipScope;
6+
tooltipScope,
7+
$document;
78

89
// load the popover code
910
beforeEach(module('ui.bootstrap.tooltip'));
@@ -15,7 +16,8 @@ describe('tooltip template', function() {
1516
$templateCache.put('myUrl', [200, '<span>{{ myTemplateText }}</span>', {}]);
1617
}));
1718

18-
beforeEach(inject(function($rootScope, $compile) {
19+
beforeEach(inject(function($rootScope, $compile, _$document_) {
20+
$document = _$document_;
1921
elmBody = angular.element(
2022
'<div><span uib-tooltip-template="templateUrl">Selector Text</span></div>'
2123
);
@@ -30,6 +32,10 @@ describe('tooltip template', function() {
3032
tooltipScope = elmScope.$$childTail;
3133
}));
3234

35+
afterEach(function() {
36+
$document.off('keypress');
37+
});
38+
3339
function trigger(element, evt) {
3440
evt = new Event(evt);
3541

src/tooltip/test/tooltip.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ describe('tooltip', function() {
2626
tooltipScope = elmScope.$$childTail;
2727
}));
2828

29+
afterEach(function() {
30+
$document.off('keypress');
31+
});
32+
2933
function trigger(element, evt) {
3034
evt = new Event(evt);
3135

src/tooltip/test/tooltip2.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ describe('tooltip directive', function() {
3737
});
3838
});
3939

40+
afterEach(function() {
41+
$document.off('keypress');
42+
});
43+
4044
function compileTooltip(ttipMarkup) {
4145
var fragment = $compile('<div>' + ttipMarkup + '</div>')($rootScope);
4246
$rootScope.$digest();

0 commit comments

Comments
 (0)