You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, I believe setSelected() is generally used to mimic user interaction, not programmatic interaction. So it follows that setSelected() should behave in the same way as a user interacting with a <select> element's <option>s, which I believe will only ever fire a change event if the selection has been modified.
@vvanpo as you said and the docs explicitly state it triggers the change event every time I don't think this is a bug. I don't think the test-utils should keep track of data and know if something has changed between two calls. If setSelected() gets called multiple times, it's fair that it does it job multiple times.
@codebryo I am a bit split here. I agree with you on that one, yet I saw that selecting the same option does not trigger an event... Do we want to emulate a user action or explicitly do what the action states.. hmmmm @afontcu@JessicaSachs Opinions here?
...even though docs say the exact same thing regarding it being an alias of setting the right value and emitting the event.
I'd say all setXXXX methods to behave the exact same way. We could make them emulate the user or not, but in a consistent way. For the record, I'd like them to stay closer to the users.
@afontcu good find, it seems clear to me that emulating user actions is the most intuitive and useful behaviour, here.
Interestingly, that same is not true when calling setChecked() on an <input type="radio" />. It used to be, but was removed in ef66c26#diff-f8b21801dcf5dee76bc9f5f22e227ea8L516, which looks to me like a regression.
Activity
vvanpo commentedon Nov 2, 2019
I hesitated to open this as a bug, as the documentation is explicit in saying that
trigger('change')
is called every time: https://github.com/vuejs/vue-test-utils/blob/v1.0.0-beta.29/docs/api/wrapper/setSelected.mdHowever, I believe
setSelected()
is generally used to mimic user interaction, not programmatic interaction. So it follows thatsetSelected()
should behave in the same way as a user interacting with a<select>
element's<option>
s, which I believe will only ever fire achange
event if the selection has been modified.dobromir-hristov commentedon Dec 15, 2019
You are correct, it only emits
change
event if select another option. It shouldnt be hard to see if an option is selected.codebryo commentedon Dec 17, 2019
@vvanpo as you said and the docs explicitly state it triggers the
change
event every time I don't think this is a bug. I don't think the test-utils should keep track of data and know if something has changed between two calls. IfsetSelected()
gets called multiple times, it's fair that it does it job multiple times.dobromir-hristov commentedon Dec 17, 2019
@codebryo I am a bit split here. I agree with you on that one, yet I saw that selecting the same option does not trigger an event... Do we want to emulate a user action or explicitly do what the action states.. hmmmm @afontcu @JessicaSachs Opinions here?
afontcu commentedon Dec 17, 2019
If I'm not mistaken,
setChecked
is not sending the event if the element is already checkedvue-test-utils/packages/test-utils/src/wrapper.js
Lines 356 to 357 in 950763f
...even though docs say the exact same thing regarding it being an alias of setting the right value and emitting the event.
I'd say all
setXXXX
methods to behave the exact same way. We could make them emulate the user or not, but in a consistent way. For the record, I'd like them to stay closer to the users.vvanpo commentedon Dec 19, 2019
@afontcu good find, it seems clear to me that emulating user actions is the most intuitive and useful behaviour, here.
Interestingly, that same is not true when calling
setChecked()
on an<input type="radio" />
. It used to be, but was removed in ef66c26#diff-f8b21801dcf5dee76bc9f5f22e227ea8L516, which looks to me like a regression.vvanpo commentedon Dec 19, 2019
If there are no objections, I'll open a PR for this.
JessicaSachs commentedon Dec 19, 2019
Yes please, @vvanpo
Merge pull request #1380 from vvanpo/set-selected