vue-js-toggle-button
vue-js-toggle-button copied to clipboard
Not able to test using jest
trafficstars
await wrapper.findComponent({ ref: "videoScaleToggle" }).trigger("click");
or
await wrapper.findComponent({ ref: "videoScaleToggle" }).trigger("change");]
these dont work in jest
For anyone else reaching this issue with the same problem: To be able to trigger an event on the toggle button, I just attached a selector to it
<toggle-button data-test-id="toggle" />
While inspecting the HTML produced, I noticed that the selector was being attached to a <label> which wraps the <input type="checkbox">. Something lke
<label data-test-id="toggle">
<input type="checkbox" />
</label>
So I updated the toggle value by calling
wrapper.find(`[data-test-id="toggle"] input`).setChecked(true)