@@ -55,6 +55,43 @@ describeWithShallowAndMount('setChecked', mountingMethod => {
5555 expect ( wrapper . find ( '.counter' ) . text ( ) ) . to . equal ( '4' )
5656 } )
5757
58+ it ( 'triggers a change event when called on a checkbox' , ( ) => {
59+ const listener = sinon . spy ( )
60+
61+ mountingMethod ( {
62+ // For compatibility with earlier versions of Vue that use the `click`
63+ // event for updating `v-model`.
64+ template : `
65+ <input
66+ type="checkbox"
67+ @change="listener"
68+ @click="listener"
69+ >
70+ ` ,
71+ methods : { listener }
72+ } ) . setChecked ( )
73+
74+ expect ( listener ) . to . have . been . called
75+ } )
76+
77+ it ( 'does not trigger a change event if the checkbox is already checked' , ( ) => {
78+ const listener = sinon . spy ( )
79+
80+ mountingMethod ( {
81+ template : `
82+ <input
83+ type="checkbox"
84+ checked
85+ @change="listener"
86+ @click="listener"
87+ >
88+ ` ,
89+ methods : { listener }
90+ } ) . setChecked ( )
91+
92+ expect ( listener ) . not . to . have . been . called
93+ } )
94+
5895 it ( 'updates dom with radio v-model' , async ( ) => {
5996 const wrapper = mountingMethod ( ComponentWithInput )
6097
@@ -67,7 +104,7 @@ describeWithShallowAndMount('setChecked', mountingMethod => {
67104 expect ( wrapper . text ( ) ) . to . contain ( 'radioFooResult' )
68105 } )
69106
70- it ( 'changes state the right amount of times with checkbox v-model' , async ( ) => {
107+ it ( 'changes state the right amount of times with radio v-model' , async ( ) => {
71108 const wrapper = mountingMethod ( ComponentWithInput )
72109 const radioBar = wrapper . find ( '#radioBar' )
73110 const radioFoo = wrapper . find ( '#radioFoo' )
@@ -89,6 +126,41 @@ describeWithShallowAndMount('setChecked', mountingMethod => {
89126 expect ( wrapper . find ( '.counter' ) . text ( ) ) . to . equal ( '4' )
90127 } )
91128
129+ it ( 'triggers a change event when called on a radio button' , ( ) => {
130+ const listener = sinon . spy ( )
131+
132+ mountingMethod ( {
133+ template : `
134+ <input
135+ type="radio"
136+ @change="listener"
137+ @click="listener"
138+ >
139+ ` ,
140+ methods : { listener }
141+ } ) . setChecked ( )
142+
143+ expect ( listener ) . to . have . been . called
144+ } )
145+
146+ it ( 'does not trigger a change event if the radio button is already checked' , ( ) => {
147+ const listener = sinon . spy ( )
148+
149+ mountingMethod ( {
150+ template : `
151+ <input
152+ type="radio"
153+ checked
154+ @change="listener"
155+ @click="listener"
156+ >
157+ ` ,
158+ methods : { listener }
159+ } ) . setChecked ( )
160+
161+ expect ( listener ) . not . to . have . been . called
162+ } )
163+
92164 it ( 'throws error if checked param is not boolean' , ( ) => {
93165 const message = 'wrapper.setChecked() must be passed a boolean'
94166 const wrapper = mountingMethod ( ComponentWithInput )
0 commit comments