@@ -1530,11 +1530,14 @@ describe('select', function() {
1530
1530
[ 'a' ] ,
1531
1531
NaN
1532
1532
] , function ( prop ) {
1533
+
1533
1534
scope . option1 = prop ;
1535
+ scope . option2 = 'red' ;
1534
1536
scope . selected = 'NOMATCH' ;
1535
1537
1536
1538
compile ( '<select ng-model="selected">' +
1537
1539
'<option ng-value="option1">{{option1}}</option>' +
1540
+ '<option ng-value="option2">{{option2}}</option>' +
1538
1541
'</select>' ) ;
1539
1542
1540
1543
scope . $digest ( ) ;
@@ -1571,10 +1574,12 @@ describe('select', function() {
1571
1574
NaN
1572
1575
] , function ( prop ) {
1573
1576
scope . option = prop ;
1577
+ scope . option2 = 'red' ;
1574
1578
scope . selected = 'NOMATCH' ;
1575
1579
1576
1580
compile ( '<select ng-model="selected">' +
1577
1581
'<option ng-value="option">{{option}}</option>' +
1582
+ '<option ng-value="option2">{{option2}}</option>' +
1578
1583
'</select>' ) ;
1579
1584
1580
1585
var selectController = element . controller ( 'select' ) ;
@@ -1604,7 +1609,7 @@ describe('select', function() {
1604
1609
1605
1610
expect ( scope . selected ) . toBe ( null ) ;
1606
1611
expect ( element [ 0 ] . selectedIndex ) . toBe ( 0 ) ;
1607
- expect ( element . find ( 'option' ) . length ) . toBe ( 2 ) ;
1612
+ expect ( element . find ( 'option' ) . length ) . toBe ( 3 ) ;
1608
1613
expect ( element . find ( 'option' ) . eq ( 0 ) . prop ( 'selected' ) ) . toBe ( true ) ;
1609
1614
expect ( element . find ( 'option' ) . eq ( 0 ) . val ( ) ) . toBe ( unknownValue ( prop ) ) ;
1610
1615
expect ( element . find ( 'option' ) . eq ( 1 ) . prop ( 'selected' ) ) . toBe ( false ) ;
@@ -1617,6 +1622,7 @@ describe('select', function() {
1617
1622
expect ( element . find ( 'option' ) . eq ( 0 ) . val ( ) ) . toBe ( 'string:UPDATEDVALUE' ) ;
1618
1623
} ) ;
1619
1624
1625
+
1620
1626
it ( 'should interact with custom attribute $observe and $set calls' , function ( ) {
1621
1627
var log = [ ] , optionAttr ;
1622
1628
@@ -1638,26 +1644,43 @@ describe('select', function() {
1638
1644
optionAttr . $set ( 'value' , 'update' ) ;
1639
1645
expect ( log [ 1 ] ) . toBe ( 'update' ) ;
1640
1646
expect ( element . find ( 'option' ) . eq ( 1 ) . val ( ) ) . toBe ( 'string:update' ) ;
1647
+ } ) ;
1648
+
1641
1649
1650
+ it ( 'should ignore the option text / value attribute if the ngValue attribute exists' , function ( ) {
1651
+ scope . ngvalue = 'abc' ;
1652
+ scope . value = 'def' ;
1653
+ scope . textvalue = 'ghi' ;
1654
+
1655
+ compile ( '<select ng-model="x"><option ng-value="ngvalue" value="{{value}}">{{textvalue}}</option></select>' ) ;
1656
+ expect ( element ) . toEqualSelect ( [ unknownValue ( undefined ) ] , 'string:abc' ) ;
1642
1657
} ) ;
1643
1658
1644
- it ( 'should ignore the option text / value attribute if the ngValue attribute exists' , function ( ) {
1645
- scope . ngvalue = 'abc' ;
1646
- scope . value = 'def' ;
1647
- scope . textvalue = 'ghi' ;
1648
1659
1649
- compile ( '<select ng-model="x"><option ng-value="ngvalue" value="{{value}}">{{textvalue}}</option></select>' ) ;
1650
- expect ( element ) . toEqualSelect ( [ unknownValue ( undefined ) ] , 'string:abc' ) ;
1651
- } ) ;
1660
+ it ( 'should ignore option text with multiple interpolations if the ngValue attribute exists' , function ( ) {
1661
+ scope . ngvalue = 'abc' ;
1662
+ scope . textvalue = 'def' ;
1663
+ scope . textvalue2 = 'ghi' ;
1652
1664
1653
- it ( 'should ignore option text with multiple interpolations if the ngValue attribute exists' , function ( ) {
1654
- scope . ngvalue = 'abc' ;
1655
- scope . textvalue = 'def' ;
1656
- scope . textvalue2 = 'ghi' ;
1665
+ compile ( '<select ng-model="x"><option ng-value="ngvalue">{{textvalue}} {{textvalue2}}</option></select>' ) ;
1666
+ expect ( element ) . toEqualSelect ( [ unknownValue ( undefined ) ] , 'string:abc' ) ;
1667
+ } ) ;
1668
+
1669
+
1670
+ it ( 'should select the first option if it is `undefined`' , function ( ) {
1671
+ scope . selected = undefined ;
1672
+
1673
+ scope . option1 = undefined ;
1674
+ scope . option2 = 'red' ;
1675
+
1676
+ compile ( '<select ng-model="selected">' +
1677
+ '<option ng-value="option1">{{option1}}</option>' +
1678
+ '<option ng-value="option2">{{option2}}</option>' +
1679
+ '</select>' ) ;
1680
+
1681
+ expect ( element ) . toEqualSelect ( [ 'undefined:undefined' ] , 'string:red' ) ;
1682
+ } ) ;
1657
1683
1658
- compile ( '<select ng-model="x"><option ng-value="ngvalue">{{textvalue}} {{textvalue2}}</option></select>' ) ;
1659
- expect ( element ) . toEqualSelect ( [ unknownValue ( undefined ) ] , 'string:abc' ) ;
1660
- } ) ;
1661
1684
1662
1685
describe ( 'and select[multiple]' , function ( ) {
1663
1686
0 commit comments