Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Closed
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
66 changes: 64 additions & 2 deletions test/ng/directive/selectSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,22 +964,84 @@ describe('select', function() {

describe('option', function() {

it('should populate value attribute on OPTION', function() {
it('should populate a missing value attribute with the option text', function() {
compile('<select ng-model="x"><option selected>abc</option></select>');
expect(element).toEqualSelect([unknownValue(undefined)], 'abc');
});

it('should ignore value if already exists', function() {

it('should ignore the option text if the value attribute exists', function() {
compile('<select ng-model="x"><option value="abc">xyz</option></select>');
expect(element).toEqualSelect([unknownValue(undefined)], 'abc');
});


it('should set value even if self closing HTML', function() {
scope.x = 'hello';
compile('<select ng-model="x"><option>hello</select>');
expect(element).toEqualSelect(['hello']);
});


it('should add options with interpolated text',
inject(function($rootScope, $compile) {
var scope = $rootScope;

scope.option1 = 'Option 1';
scope.option2 = 'Option 2';

var element = $compile(
'<select ng-model="selected">' +
'<option>{{option1}}</option>' +
'<option>{{option2}}</option>' +
'</div>')(scope);

scope.$digest();
expect(scope.selected).toBeUndefined();

browserTrigger(element.find('option').eq(0));
expect(scope.selected).toBe('Option 1');

scope.selected = 'Option 2';
scope.$digest();
expect(element.find('option').eq(1).prop('selected')).toBe(true);
expect(element.find('option').eq(1).text()).toBe('Option 2');

//Make sure the bindings are destroyed
dealoc(element);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not completely sure if this is the best way to make sure the text bindings are destroyed. (without this line, it complains about leaking bindings)

})
);


it('should update options when their interpolated text changes',
inject(function($rootScope, $compile) {
var scope = $rootScope;

scope.option1 = 'Option 1';
scope.option2 = 'Option 2';

var element = $compile(
'<select ng-model="selected">' +
'<option>{{option1}}</option>' +
'<option>{{option2}}</option>' +
'</div>')(scope);

scope.$digest();
expect(scope.selected).toBeUndefined();

//Change value of option2
scope.option2 = 'Option 2 Changed';

scope.selected = 'Option 2 Changed';
scope.$digest();
expect(element.find('option').eq(1).prop('selected')).toBe(true);
expect(element.find('option').eq(1).text()).toBe('Option 2 Changed');

//Make sure the bindings are destroyed
dealoc(element);
})
);

it('should not blow up when option directive is found inside of a datalist',
inject(function($compile, $rootScope) {
var element = $compile('<div>' +
Expand Down