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

Commit

Permalink
update(tests): improve cleanup afterEach
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBurleson committed Aug 21, 2015
1 parent d9ba0e1 commit e22cd6b
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 15 deletions.
24 changes: 24 additions & 0 deletions src/components/autocomplete/autocomplete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ describe('<md-autocomplete>', function () {

expect(scope.searchText).toBe('foo');
expect(scope.selectedItem).toBe(scope.match(scope.searchText)[ 0 ]);

element.remove();
}));

it('should allow you to set an input id without floating label', inject(function () {
Expand All @@ -86,6 +88,8 @@ describe('<md-autocomplete>', function () {
var input = element.find('input');

expect(input.attr('id')).toBe(scope.inputId);

element.remove();
}));

it('should allow you to set an input id with floating label', inject(function () {
Expand All @@ -105,6 +109,8 @@ describe('<md-autocomplete>', function () {
var input = element.find('input');

expect(input.attr('id')).toBe(scope.inputId);

element.remove();
}));

it('should clear value when hitting escape', inject(function ($mdConstant, $timeout) {
Expand All @@ -131,6 +137,8 @@ describe('<md-autocomplete>', function () {
scope.$apply(function () { ctrl.keydown(keydownEvent($mdConstant.KEY_CODE.ESCAPE)); });

expect(scope.searchText).toBe('');

element.remove();
}));
});

Expand Down Expand Up @@ -168,6 +176,8 @@ describe('<md-autocomplete>', function () {

expect(scope.searchText).toBe('foo');
expect(scope.selectedItem).toBe(scope.match(scope.searchText)[ 0 ]);

element.remove();
}));
});

Expand Down Expand Up @@ -197,6 +207,8 @@ describe('<md-autocomplete>', function () {
expect(scope.match(scope.searchText).length).toBe(1);
expect(ul.find('li').length).toBe(1);
expect(ul.find('li').find('img').length).toBe(0);

element.remove();
});
});

Expand Down Expand Up @@ -231,6 +243,8 @@ describe('<md-autocomplete>', function () {

expect(scope.searchText).toBe('');
expect(scope.selectedItem).toBe(null);

element.remove();
}));

it('should notify selected item watchers', inject(function ($timeout) {
Expand Down Expand Up @@ -278,6 +292,8 @@ describe('<md-autocomplete>', function () {
expect(scope.itemChanged.calls.count()).toBe(2);
expect(scope.itemChanged.calls.mostRecent().args[ 0 ]).toBeNull();
expect(scope.selectedItem).toBeNull();

element.remove();
}));
it('should pass value to item watcher', inject(function ($timeout) {
var scope = createScope();
Expand Down Expand Up @@ -309,6 +325,8 @@ describe('<md-autocomplete>', function () {

ctrl.clear();
element.scope().$apply();

element.remove();
}));
});

Expand All @@ -335,6 +353,8 @@ describe('<md-autocomplete>', function () {

expect(scope.selectedItem).not.toBe(null);
expect(scope.selectedItem.display).toBe('foo');

element.remove();
}));
it('should not select matching item on exact match when `md-select-on-match` is NOT toggled', inject(function ($timeout) {
var scope = createScope();
Expand All @@ -356,6 +376,8 @@ describe('<md-autocomplete>', function () {
$timeout.flush();

expect(scope.selectedItem).toBe(null);

element.remove();
}));
});

Expand All @@ -376,6 +398,8 @@ describe('<md-autocomplete>', function () {
scope.$apply();

expect(element.html()).toBe('<span class="highlight">so</span>me more text');

element.remove();
}));
});

Expand Down
11 changes: 11 additions & 0 deletions src/components/chips/chips.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
describe('<md-chips>', function() {
var attachedElements = [];
var scope, $exceptionHandler, $timeout;

var BASIC_CHIP_TEMPLATE =
'<md-chips ng-model="items"></md-chips>';
var CHIP_APPEND_TEMPLATE =
Expand All @@ -13,6 +15,14 @@ describe('<md-chips>', function() {
' <md-autocomplete md-items="item in [\'hi\', \'ho\', \'he\']"></md-autocomplete>' +
'</md-chips>';

afterEach(function() {
attachedElements.forEach(function(element) {
element.remove();
});
attachedElements = [];
});


describe('with no overrides', function() {
beforeEach(module('material.components.chips', 'material.components.autocomplete'));
beforeEach(inject(function($rootScope, _$exceptionHandler_, _$timeout_) {
Expand Down Expand Up @@ -421,6 +431,7 @@ describe('<md-chips>', function() {
container = $compile(str)(scope);
container.scope().$apply();
});
attachedElements.push(container);
return container;
}

Expand Down
39 changes: 24 additions & 15 deletions src/components/chips/contact-chips.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,36 @@ describe('<md-contact-chips>', function() {

beforeEach(module('material.components.chips'));

beforeEach(inject(function ($rootScope) {
beforeEach(inject(function($rootScope) {
scope = $rootScope.$new();
var img = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
scope.allContacts = [
{
name : 'NAME',
email : 'email',
image : img
},{
name : 'NAME2',
email : 'email2',
image : img
},{
name : 'NAME3',
email : 'email3',
image : img
name: 'NAME',
email: 'email',
image: img
}, {
name: 'NAME2',
email: 'email2',
image: img
}, {
name: 'NAME3',
email: 'email3',
image: img
}
];
scope.contacts = [];
}));

describe('basic functionality', function () {
var attachedElements = [];
afterEach(function() {
attachedElements.forEach(function(element) {
element.remove();
});
attachedElements = [];
});

describe('basic functionality', function() {
it('should show the placeholder', inject(function($timeout) {
var element = buildChips(CONTACT_CHIPS_TEMPLATE);
var ctrl = element.controller('mdContactChips');
Expand Down Expand Up @@ -91,12 +99,13 @@ describe('<md-contact-chips>', function() {
// Internal helper methods
// *******************************

function buildChips (str) {
function buildChips(str) {
var container;
inject(function ($compile) {
inject(function($compile) {
container = $compile(str)(scope);
container.scope().$apply();
});
attachedElements.push(container);
return container;
}

Expand Down
10 changes: 10 additions & 0 deletions src/components/list/list.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
describe('mdListItem directive', function() {
var attachedElements = [];
var $compile, $rootScope;

beforeEach(module('material.components.list', 'material.components.checkbox', 'material.components.switch'));
Expand All @@ -7,12 +8,21 @@ describe('mdListItem directive', function() {
$rootScope = _$rootScope_;
}));

afterEach(function() {
attachedElements.forEach(function(element) {
element.remove();
});
attachedElements = [];
});

function setup(html) {
var el;
inject(function($compile, $rootScope) {
el = $compile(html)($rootScope);
$rootScope.$apply();
});
attachedElements.push(el);

return el;
}

Expand Down
6 changes: 6 additions & 0 deletions src/components/menu/menu.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
describe('material.components.menu', function() {
var attachedElements = [];
var $mdMenu, $timeout, menuActionPerformed, $mdUtil;

beforeEach(module('material.components.menu'));
Expand All @@ -11,6 +12,10 @@ describe('material.components.menu', function() {
}));
afterEach(function() {
menuActionPerformed = false;
attachedElements.forEach(function(element) {
element.remove();
});
attachedElements = [];
});

describe('md-menu directive', function() {
Expand Down Expand Up @@ -178,6 +183,7 @@ describe('material.components.menu', function() {
menu = $compile(template)($rootScope);
});

attachedElements.push(menu);
return menu;
}
});
Expand Down
13 changes: 13 additions & 0 deletions src/components/select/select.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
describe('<md-select>', function() {
var attachedElements = [];

afterEach(function() {
attachedElements.forEach(function(element) {
element.remove();
});
attachedElements = [];
});

beforeEach(module('material.components.input'));
beforeEach(module('material.components.select'));


function setupSelect(attrs, options, bNoLabel) {
var el;

Expand All @@ -16,6 +25,8 @@ describe('<md-select>', function() {
el = $compile(template)($rootScope);
$rootScope.$digest();
});
attachedElements.push(el);

return el;
}

Expand All @@ -28,6 +39,8 @@ describe('<md-select>', function() {
el = $compile(fullTpl)($rootScope);
$rootScope.$apply();
});
attachedElements.push(el);

return el;
}

Expand Down

0 comments on commit e22cd6b

Please sign in to comment.