This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(select): assign result of track exp to element value #9726
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -726,6 +726,19 @@ describe('select', function() { | |
}); | ||
|
||
|
||
it('should use the tracked expression as option value', function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space between |
||
createSelect({ | ||
'ng-model': 'selected', | ||
'ng-options': 'item.label for item in arr track by item.id' | ||
}); | ||
|
||
var options = element.find('option'); | ||
expect(options.length).toEqual(3); | ||
expect(sortedHtml(options[0])).toEqual('<option value="?"></option>'); | ||
expect(sortedHtml(options[1])).toEqual('<option value="10">ten</option>'); | ||
expect(sortedHtml(options[2])).toEqual('<option value="20">twenty</option>'); | ||
}); | ||
|
||
it('should preserve value even when reference has changed (single&array)', function() { | ||
createSelect({ | ||
'ng-model': 'selected', | ||
|
@@ -735,12 +748,12 @@ describe('select', function() { | |
scope.$apply(function() { | ||
scope.selected = scope.arr[0]; | ||
}); | ||
expect(element.val()).toBe('0'); | ||
expect(element.val()).toBe('10'); | ||
|
||
scope.$apply(function() { | ||
scope.arr[0] = {id: 10, label: 'new ten'}; | ||
}); | ||
expect(element.val()).toBe('0'); | ||
expect(element.val()).toBe('10'); | ||
|
||
element.children()[1].selected = 1; | ||
browserTrigger(element, 'change'); | ||
|
@@ -758,12 +771,12 @@ describe('select', function() { | |
scope.$apply(function() { | ||
scope.selected = scope.arr; | ||
}); | ||
expect(element.val()).toEqual(['0','1']); | ||
expect(element.val()).toEqual(['10','20']); | ||
|
||
scope.$apply(function() { | ||
scope.arr[0] = {id: 10, label: 'new ten'}; | ||
}); | ||
expect(element.val()).toEqual(['0','1']); | ||
expect(element.val()).toEqual(['10','20']); | ||
|
||
element.children()[0].selected = false; | ||
browserTrigger(element, 'change'); | ||
|
@@ -840,16 +853,16 @@ describe('select', function() { | |
scope.$apply(function() { | ||
scope.selected = scope.arr[0].subItem; | ||
}); | ||
expect(element.val()).toEqual('0'); | ||
expect(element.val()).toEqual('10'); | ||
|
||
scope.$apply(function() { | ||
scope.selected = scope.arr[1].subItem; | ||
}); | ||
expect(element.val()).toEqual('1'); | ||
expect(element.val()).toEqual('20'); | ||
|
||
// Now test view -> model | ||
|
||
element.val('0'); | ||
element.val('10'); | ||
browserTrigger(element, 'change'); | ||
expect(scope.selected).toBe(scope.arr[0].subItem); | ||
|
||
|
@@ -861,7 +874,7 @@ describe('select', function() { | |
subItem: {label: 'new twenty', id: 20} | ||
}]; | ||
}); | ||
expect(element.val()).toBe('0'); | ||
expect(element.val()).toBe('10'); | ||
expect(scope.selected.id).toBe(10); | ||
}); | ||
|
||
|
@@ -879,12 +892,12 @@ describe('select', function() { | |
scope.$apply(function() { | ||
scope.selected = [scope.arr[0].subItem]; | ||
}); | ||
expect(element.val()).toEqual(['0']); | ||
expect(element.val()).toEqual(['10']); | ||
|
||
scope.$apply(function() { | ||
scope.selected = [scope.arr[1].subItem]; | ||
}); | ||
expect(element.val()).toEqual(['1']); | ||
expect(element.val()).toEqual(['20']); | ||
|
||
// Now test view -> model | ||
|
||
|
@@ -901,7 +914,7 @@ describe('select', function() { | |
subItem: {label: 'new twenty', id: 20} | ||
}]; | ||
}); | ||
expect(element.val()).toEqual(['0']); | ||
expect(element.val()).toEqual(['10']); | ||
expect(scope.selected[0].id).toEqual(10); | ||
expect(scope.selected.length).toBe(1); | ||
}); | ||
|
@@ -1338,20 +1351,20 @@ describe('select', function() { | |
scope.selected = scope.values[1]; | ||
}); | ||
|
||
expect(element.val()).toEqual('1'); | ||
expect(element.val()).toEqual('2'); | ||
|
||
var first = jqLite(element.find('option')[0]); | ||
expect(first.text()).toEqual('first'); | ||
expect(first.attr('value')).toEqual('0'); | ||
expect(first.attr('value')).toEqual('1'); | ||
var forth = jqLite(element.find('option')[3]); | ||
expect(forth.text()).toEqual('forth'); | ||
expect(forth.attr('value')).toEqual('3'); | ||
expect(forth.attr('value')).toEqual('4'); | ||
|
||
scope.$apply(function() { | ||
scope.selected = scope.values[3]; | ||
}); | ||
|
||
expect(element.val()).toEqual('3'); | ||
expect(element.val()).toEqual('4'); | ||
}); | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after
(trackFn)
before{