@@ -200,6 +200,42 @@ describe('select', function() {
200
200
201
201
describe ( 'empty option' , function ( ) {
202
202
203
+ it ( 'should allow dynamic empty option' , function ( ) {
204
+ scope . dynamicOptions = [ ] ;
205
+
206
+ compile ( '<select ng-model="dynamicEmpty">' +
207
+ '<option ng-repeat="opt in dynamicOptions" value="{{opt.val}}">' +
208
+ '{{opt.display}}' +
209
+ '</option>' +
210
+ '</selec>' ) ;
211
+
212
+ expect ( element . find ( 'option' ) . length ) . toBe ( 1 , 'Initially there will be one empty option' ) ;
213
+ expect ( element . find ( 'option' ) . val ( ) ) . toBe ( '? undefined:undefined ?' , 'Initially there will be one empty option with value ?' ) ;
214
+
215
+ // when dynamicOptions change and one of the elements is empty option self.emptyOption in directive should be defined
216
+ scope . dynamicOptions = [
217
+ {
218
+ val : '' ,
219
+ display : 'All Options'
220
+ } ,
221
+ {
222
+ val : '1' ,
223
+ display : 'First Option'
224
+ }
225
+ ] ;
226
+ scope . dynamicEmpty = '' ;
227
+
228
+ scope . $digest ( ) ;
229
+
230
+ expect ( element . find ( 'option' ) . length ) . toBe ( 2 , 'There should be two option now' ) ;
231
+
232
+ expect ( angular . element ( element . find ( 'option' ) [ 0 ] ) . val ( ) ) . toBe ( '' , 'First value should be empty' ) ;
233
+ expect ( angular . element ( element . find ( 'option' ) [ 0 ] ) . text ( ) ) . toBe ( 'All Options' , 'First text should be "All Options"' ) ;
234
+ expect ( angular . element ( element . find ( 'option' ) [ 1 ] ) . val ( ) ) . toBe ( '1' , 'Second value should be empty' ) ;
235
+ expect ( angular . element ( element . find ( 'option' ) [ 1 ] ) . text ( ) ) . toBe ( 'First Option' , 'Second text should be "First Option"' ) ;
236
+
237
+ } ) ;
238
+
203
239
it ( 'should select the empty option when model is undefined' , function ( ) {
204
240
compile ( '<select ng-model="robot">' +
205
241
'<option value="">--select--</option>' +
0 commit comments