@@ -4,15 +4,15 @@ describe('Directive v-model dynamic input type', () => {
4
4
it ( 'should work' , done => {
5
5
const vm = new Vue ( {
6
6
data : {
7
- type : null ,
7
+ inputType : null ,
8
8
test : 'b'
9
9
} ,
10
- template : `<input :type="type " v-model="test">`
10
+ template : `<input :type="inputType " v-model="test">`
11
11
} ) . $mount ( )
12
12
document . body . appendChild ( vm . $el )
13
13
14
14
// test text
15
- assertInputWorks ( vm ) . then ( done )
15
+ assertInputWorks ( vm , 'inputType' ) . then ( done )
16
16
} )
17
17
18
18
it ( 'with v-if' , done => {
@@ -87,7 +87,11 @@ describe('Directive v-model dynamic input type', () => {
87
87
} )
88
88
} )
89
89
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
+ }
91
95
if ( ! chain ) chain = waitForUpdate ( )
92
96
chain . then ( ( ) => {
93
97
expect ( vm . $el . value ) . toBe ( 'b' )
@@ -99,7 +103,7 @@ function assertInputWorks (vm, chain) {
99
103
expect ( vm . test ) . toBe ( 'c' )
100
104
} ) . then ( ( ) => {
101
105
// change it to password
102
- vm . type = 'password'
106
+ vm [ type ] = 'password'
103
107
vm . test = 'b'
104
108
} ) . then ( ( ) => {
105
109
expect ( vm . $el . type ) . toBe ( 'password' )
@@ -109,7 +113,7 @@ function assertInputWorks (vm, chain) {
109
113
expect ( vm . test ) . toBe ( 'c' )
110
114
} ) . then ( ( ) => {
111
115
// change it to checkbox...
112
- vm . type = 'checkbox'
116
+ vm [ type ] = 'checkbox'
113
117
} ) . then ( ( ) => {
114
118
expect ( vm . $el . type ) . toBe ( 'checkbox' )
115
119
expect ( vm . $el . checked ) . toBe ( true )
0 commit comments