@@ -40,7 +40,7 @@ describe('<select selectize>', function() {
4040
4141 function testSelectedOption ( value ) {
4242 var domOptions = selectElement . find ( 'option' ) ;
43- var selectedOption = scope . options [ parseInt ( domOptions . attr ( 'value' ) , 10 ) ] ;
43+ var selectedOption = scope . options [ parseInt ( domOptions . attr ( 'value' ) , 10 ) ] || '' ;
4444 assert . strictEqual ( domOptions . length , 1 ) ;
4545 assert . ok ( domOptions . attr ( 'selected' ) ) ;
4646 assert . equal ( selectedOption . value || selectedOption , value ) ;
@@ -107,26 +107,50 @@ describe('<select selectize>', function() {
107107 } ) ;
108108
109109 describe ( 'when both the model and the options are updated' , function ( ) {
110- it ( 'should have the same number of options in the dropdown menu as scope.options' , function ( ) {
111- assert . strictEqual ( selectize . $dropdown_content . children ( ) . length , scope . options . length ) ;
110+ describe ( 'when both the model and options start empty' , function ( ) {
111+ beforeEach ( function ( ) {
112+ scope . selection = undefined ;
113+ scope . options = [ ] ;
114+ scope . $apply ( ) ;
115+ timeout . flush ( ) ;
116+ } ) ;
112117
113- scope . selection = 'bar' ;
114- scope . options . push ( 'qux' ) ;
115- scope . $apply ( ) ;
116- timeout . flush ( ) ;
118+ it ( 'should update the selection' , function ( ) {
119+ testSelectedOption ( '' ) ;
120+
121+ scope . selection = 'foo' ;
122+ scope . $apply ( ) ;
123+ scope . options = [ 'foo' , 'bar' , 'baz' ] ;
124+ scope . $apply ( ) ;
125+ timeout . flush ( ) ;
126+
127+ testSelectedOption ( 'foo' ) ;
128+ } ) ;
117129
118- assert . strictEqual ( selectize . $dropdown_content . children ( ) . length , scope . options . length ) ;
119130 } ) ;
120131
121- it ( 'should update the selection' , function ( ) {
122- testSelectedOption ( 'foo' ) ;
132+ describe ( 'when both the model and options start non-empty' , function ( ) {
133+ it ( 'should have the same number of options in the dropdown menu as scope.options' , function ( ) {
134+ assert . strictEqual ( selectize . $dropdown_content . children ( ) . length , scope . options . length ) ;
123135
124- scope . selection = 'bar' ;
125- scope . options . push ( 'qux' ) ;
126- scope . $apply ( ) ;
127- timeout . flush ( ) ;
136+ scope . selection = 'bar' ;
137+ scope . options . push ( 'qux' ) ;
138+ scope . $apply ( ) ;
139+ timeout . flush ( ) ;
128140
129- testSelectedOption ( 'bar' ) ;
141+ assert . strictEqual ( selectize . $dropdown_content . children ( ) . length , scope . options . length ) ;
142+ } ) ;
143+
144+ it ( 'should update the selection' , function ( ) {
145+ testSelectedOption ( 'foo' ) ;
146+
147+ scope . selection = 'bar' ;
148+ scope . options . push ( 'qux' ) ;
149+ scope . $apply ( ) ;
150+ timeout . flush ( ) ;
151+
152+ testSelectedOption ( 'bar' ) ;
153+ } ) ;
130154 } ) ;
131155 } ) ;
132156 } ) ;
0 commit comments