@@ -95,26 +95,26 @@ function describeFunctions(inputElement){
9595 } ) ;
9696} ;
9797
98- function describeAttributes ( inputElement , exclude = [ ] ) {
98+ function describeAttributes ( inputElement , testPlaceholder = true ) {
9999 beforeEach ( ( ) => {
100100 data . form . test . type = inputElement ;
101101 data . form . test . inputType = 'text' ;
102102 } ) ;
103103
104104 it ( 'attributes' , ( ) => {
105- if ( exclude . indexOf ( 'attributes' ) >= 0 ) return true ;
106105 data . form . test . atts = {
107106 'data-foo' : 'bar' ,
108- 'data-bar' : 'foo'
107+ 'data-bar' : 'foo' ,
108+ 'placeholder' : 'holding'
109109 } ;
110110 createForm ( ) ;
111111 let input = vm . $el . querySelectorAll ( inputElement ) [ 0 ] ;
112112 expect ( input . dataset . foo ) . to . equal ( 'bar' ) ;
113113 expect ( input . dataset . bar ) . to . equal ( 'foo' ) ;
114+ if ( testPlaceholder ) expect ( input . placeholder ) . to . equal ( 'holding' ) ;
114115 } ) ;
115116
116117 it ( 'classes' , ( ) => {
117- if ( exclude . indexOf ( 'classes' ) >= 0 ) return true ;
118118 data . form . test . classes = {
119119 'class-a' : true ,
120120 'class-b' : false
@@ -124,18 +124,7 @@ function describeAttributes(inputElement, exclude = []){
124124 expect ( input . className ) . to . equal ( 'form-control class-a' ) ;
125125 } ) ;
126126
127-
128-
129- it ( 'placeholder' , ( ) => {
130- if ( exclude . indexOf ( 'placeholder' ) >= 0 ) return ;
131- data . form . test . placeholder = 'holding' ;
132- createForm ( ) ;
133- let input = vm . $el . querySelectorAll ( inputElement ) [ 0 ] ;
134- expect ( input . placeholder ) . to . equal ( 'holding' ) ;
135- } ) ;
136-
137127 it ( 'id' , ( ) => {
138- if ( exclude . indexOf ( 'id' ) >= 0 ) return true ;
139128 data . form . test . id = 'someId' ;
140129 createForm ( ) ;
141130 let input = vm . $el . querySelectorAll ( inputElement ) [ 0 ] ;
@@ -219,7 +208,7 @@ describe('Bootstrap Field Inputs', () => {
219208 describeFunctions ( 'select' ) ;
220209 } ) ;
221210 describe ( 'classes & attributes' , ( ) => {
222- describeAttributes ( 'select' , [ 'placeholder' ] ) ;
211+ describeAttributes ( 'select' , false ) ;
223212 } ) ;
224213 describe ( 'conditional elements' , ( ) => {
225214 describeConditional ( 'select' ) ;
@@ -234,6 +223,31 @@ describe('Bootstrap Field Inputs', () => {
234223
235224 expect ( inputs ) . to . be . length ( 1 ) ;
236225 } ) ;
226+
227+ it ( 'array options' , ( ) => {
228+ data . form . test . type = 'select' ;
229+ data . form . test . options = [ 'one' , 'two' , 'three' ] ;
230+ createForm ( ) ;
231+ let options = vm . $el . querySelectorAll ( 'option' ) ;
232+ let option = options [ 0 ] ;
233+ expect ( options ) . to . be . length ( 3 ) ;
234+ expect ( option . value ) . to . equal ( 'one' ) ;
235+ expect ( option . innerHTML ) . to . equal ( 'one' ) ;
236+ } ) ;
237+
238+ it ( 'object options' , ( ) => {
239+ data . form . test . type = 'select' ;
240+ data . form . test . options = [
241+ { label : 'Foo' , value : 'bar' } ,
242+ { label : 'Bar' , value : 'foo' }
243+ ] ;
244+ createForm ( ) ;
245+ let options = vm . $el . querySelectorAll ( 'option' ) ;
246+ let option = options [ 0 ] ;
247+ expect ( options ) . to . be . length ( 2 ) ;
248+ expect ( option . value ) . to . equal ( 'bar' ) ;
249+ expect ( option . innerHTML ) . to . equal ( 'Foo' ) ;
250+ } ) ;
237251
238252 } ) ;
239253
0 commit comments