mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
test(selectSpec): clean up and simplify specs
This commit is contained in:
parent
8ebe5ccd9a
commit
c65c34ebfe
1 changed files with 39 additions and 39 deletions
|
|
@ -10,12 +10,34 @@ describe('select', function() {
|
|||
scope.$apply();
|
||||
}
|
||||
|
||||
|
||||
beforeEach(inject(function($injector, $rootScope) {
|
||||
scope = $rootScope;
|
||||
$compile = $injector.get('$compile');
|
||||
formElement = element = null;
|
||||
}));
|
||||
|
||||
|
||||
beforeEach(function() {
|
||||
this.addMatchers({
|
||||
toEqualSelect: function(expected){
|
||||
var actualValues = [],
|
||||
expectedValues = [].slice.call(arguments);
|
||||
|
||||
forEach(this.actual.find('option'), function(option) {
|
||||
actualValues.push(option.selected ? [option.value] : option.value);
|
||||
});
|
||||
|
||||
this.message = function() {
|
||||
return 'Expected ' + toJson(actualValues) + ' to equal ' + toJson(expectedValues) + '.';
|
||||
};
|
||||
|
||||
return equals(expectedValues, actualValues);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
afterEach(function() {
|
||||
dealoc(formElement);
|
||||
});
|
||||
|
|
@ -102,15 +124,13 @@ describe('select', function() {
|
|||
scope.selection = ['A'];
|
||||
});
|
||||
|
||||
expect(element.find('option')[0].selected).toEqual(true);
|
||||
expect(element.find('option')[1].selected).toEqual(false);
|
||||
expect(element).toEqualSelect(['A'], 'B');
|
||||
|
||||
scope.$apply(function() {
|
||||
scope.selection.push('B');
|
||||
});
|
||||
|
||||
expect(element.find('option')[0].selected).toEqual(true);
|
||||
expect(element.find('option')[1].selected).toEqual(true);
|
||||
expect(element).toEqualSelect(['A'], ['B']);
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -817,47 +837,27 @@ describe('select', function() {
|
|||
|
||||
|
||||
describe('OPTION value', function() {
|
||||
beforeEach(function() {
|
||||
this.addMatchers({
|
||||
toHaveValue: function(expected){
|
||||
this.message = function() {
|
||||
return 'Expected "' + this.actual.html() + '" to have value="' + expected + '".';
|
||||
};
|
||||
|
||||
var value;
|
||||
htmlParser(this.actual.html(), {
|
||||
start:function(tag, attrs){
|
||||
value = attrs.value;
|
||||
},
|
||||
end:noop,
|
||||
chars:noop
|
||||
});
|
||||
return trim(value) == trim(expected);
|
||||
}
|
||||
});
|
||||
it('should populate value attribute on OPTION', function() {
|
||||
compile('<select ng-model="x"><option selected>abc</option></select>');
|
||||
expect(element).toEqualSelect('abc');
|
||||
});
|
||||
|
||||
it('should ignore value if already exists', function() {
|
||||
compile('<select ng-model="x"><option value="abc">xyz</option></select>');
|
||||
expect(element).toEqualSelect('abc');
|
||||
});
|
||||
|
||||
it('should populate value attribute on OPTION', inject(function($rootScope, $compile) {
|
||||
element = $compile('<select ng-model="x"><option>abc</option></select>')($rootScope)
|
||||
expect(element).toHaveValue('abc');
|
||||
}));
|
||||
it('should set value even if newlines present', function() {
|
||||
compile('<select ng-model="x"><option attr="\ntext\n" \n>\nabc\n</option></select>');
|
||||
expect(element).toEqualSelect('\nabc\n');
|
||||
});
|
||||
|
||||
it('should ignore value if already exists', inject(function($rootScope, $compile) {
|
||||
element = $compile('<select ng-model="x"><option value="abc">xyz</option></select>')($rootScope)
|
||||
expect(element).toHaveValue('abc');
|
||||
}));
|
||||
|
||||
it('should set value even if newlines present', inject(function($rootScope, $compile) {
|
||||
element = $compile('<select ng-model="x"><option attr="\ntext\n" \n>\nabc\n</option></select>')($rootScope)
|
||||
expect(element).toHaveValue('\nabc\n');
|
||||
}));
|
||||
|
||||
it('should set value even if self closing HTML', inject(function($rootScope, $compile) {
|
||||
it('should set value even if self closing HTML', function() {
|
||||
// IE removes the \n from option, which makes this test pointless
|
||||
if (msie) return;
|
||||
element = $compile('<select ng-model="x"><option>\n</option></select>')($rootScope)
|
||||
expect(element).toHaveValue('\n');
|
||||
}));
|
||||
compile('<select ng-model="x"><option>\n</option></select>');
|
||||
expect(element).toEqualSelect('\n');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue