@@ -4,15 +4,15 @@ describe('Directive v-model dynamic input type', () => {
44 it ( 'should work' , done => {
55 const vm = new Vue ( {
66 data : {
7- type : null ,
7+ inputType : null ,
88 test : 'b'
99 } ,
10- template : `<input :type="type " v-model="test">`
10+ template : `<input :type="inputType " v-model="test">`
1111 } ) . $mount ( )
1212 document . body . appendChild ( vm . $el )
1313
1414 // test text
15- assertInputWorks ( vm ) . then ( done )
15+ assertInputWorks ( vm , 'inputType' ) . then ( done )
1616 } )
1717
1818 it ( 'with v-if' , done => {
@@ -87,7 +87,11 @@ describe('Directive v-model dynamic input type', () => {
8787 } )
8888} )
8989
90- function assertInputWorks ( vm , chain ) {
90+ function assertInputWorks ( vm , type , chain ) {
91+ if ( typeof type !== 'string' ) {
92+ if ( ! chain ) chain = type
93+ type = 'type'
94+ }
9195 if ( ! chain ) chain = waitForUpdate ( )
9296 chain . then ( ( ) => {
9397 expect ( vm . $el . value ) . toBe ( 'b' )
@@ -99,7 +103,7 @@ function assertInputWorks (vm, chain) {
99103 expect ( vm . test ) . toBe ( 'c' )
100104 } ) . then ( ( ) => {
101105 // change it to password
102- vm . type = 'password'
106+ vm [ type ] = 'password'
103107 vm . test = 'b'
104108 } ) . then ( ( ) => {
105109 expect ( vm . $el . type ) . toBe ( 'password' )
@@ -109,7 +113,7 @@ function assertInputWorks (vm, chain) {
109113 expect ( vm . test ) . toBe ( 'c' )
110114 } ) . then ( ( ) => {
111115 // change it to checkbox...
112- vm . type = 'checkbox'
116+ vm [ type ] = 'checkbox'
113117 } ) . then ( ( ) => {
114118 expect ( vm . $el . type ) . toBe ( 'checkbox' )
115119 expect ( vm . $el . checked ) . toBe ( true )
0 commit comments