Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit d81ca23

Browse files
crisbetoThomasBurleson
authored andcommitted
chore(chips, datepicker, select): clean up test leaks in angular < 1.5 (#9687)
Fixes unit tests in the chips, contact chips, datepicker and select components that were leaking elements in older Angular version. This was causing other tests to fail.
1 parent 3d73e2d commit d81ca23

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

src/components/chips/chips.spec.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ describe('<md-chips>', function() {
2323

2424
afterEach(function() {
2525
attachedElements.forEach(function(element) {
26+
var scope = element.scope();
27+
28+
scope && scope.$destroy();
2629
element.remove();
2730
});
2831
attachedElements = [];
@@ -308,7 +311,7 @@ describe('<md-chips>', function() {
308311
});
309312

310313
});
311-
314+
312315
describe('when removable', function() {
313316

314317
it('should not append the input div when not removable and readonly is enabled', function() {
@@ -1173,8 +1176,6 @@ describe('<md-chips>', function() {
11731176

11741177
expect(scope.items.length).toBe(2);
11751178
expect(document.activeElement).toBe(input[0]);
1176-
1177-
element.remove();
11781179
});
11791180
});
11801181

src/components/chips/contact-chips.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ describe('<md-contact-chips>', function() {
3939
var attachedElements = [];
4040
afterEach(function() {
4141
attachedElements.forEach(function(element) {
42+
var scope = element.scope();
43+
44+
scope && scope.$destroy();
4245
element.remove();
4346
});
4447
attachedElements = [];

src/components/datepicker/js/datepickerDirective.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ describe('md-datepicker', function() {
4343
createDatepickerInstance(DATEPICKER_TEMPLATE);
4444
controller.closeCalendarPane();
4545
}));
46+
47+
afterEach(function() {
48+
controller.isAttached && controller.closeCalendarPane();
49+
pageScope.$destroy();
50+
ngElement.remove();
51+
});
52+
4653
/**
4754
* Compile and link the given template and store values for element, scope, and controller.
4855
* @param {string} template

src/components/select/select.spec.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ describe('<md-select>', function() {
1919

2020
afterEach(inject(function($document) {
2121
attachedElements.forEach(function(element) {
22+
var scope = element.scope();
23+
24+
scope && scope.$destroy();
2225
element.remove();
2326
});
2427
attachedElements = [];
@@ -510,7 +513,10 @@ describe('<md-select>', function() {
510513
});
511514

512515
it('does not allow keydown events to propagate from inside the md-select-menu', inject(function($rootScope, $compile) {
513-
$rootScope.val = [1];
516+
var scope = $rootScope.$new();
517+
518+
scope.val = [1];
519+
514520
var select = $compile(
515521
'<md-input-container>' +
516522
' <label>Label</label>' +
@@ -519,22 +525,25 @@ describe('<md-select>', function() {
519525
' <md-option value="2">Two</md-option>' +
520526
' <md-option value="3">Three</md-option>' +
521527
' </md-select>' +
522-
'</md-input-container>')($rootScope);
528+
'</md-input-container>')(scope);
523529

524530
var mdOption = select.find('md-option');
525531
var selectMenu = select.find('md-select-menu');
526532
var keydownEvent = {
527-
type: 'keydown',
528-
target: mdOption[0],
529-
preventDefault: jasmine.createSpy(),
530-
stopPropagation: jasmine.createSpy()
533+
type: 'keydown',
534+
target: mdOption[0],
535+
preventDefault: jasmine.createSpy(),
536+
stopPropagation: jasmine.createSpy()
531537
};
532538

533539
openSelect(select);
534540
angular.element(selectMenu).triggerHandler(keydownEvent);
535541

536542
expect(keydownEvent.preventDefault).toHaveBeenCalled();
537543
expect(keydownEvent.stopPropagation).toHaveBeenCalled();
544+
545+
scope.$destroy();
546+
select.remove();
538547
}));
539548

540549
it('supports raw html', inject(function($rootScope, $compile, $sce) {

0 commit comments

Comments
 (0)