Description
Subject of the issue
Code under test:
<div @click.left="onLeftClick" @click.right="onRightClick">
trigger
does not handle modifiers for 'click'
as well as buttons in option. Its not possible to test a right click neither with
wrapper.find('div').trigger('click.right');
nor with
wrapper.find('div').trigger('click', { button: 2 });
The last one is suggested by the docs here: https://vue-test-utils.vuejs.org/api/wrapper/#trigger (with button: 0
)
Steps to reproduce
Minimal project to reproduce: https://github.com/carlos22/vue2-test-utils-trigger-click-modifiers
npm run test [11:23:41] > vue2-test-utils-trigger-click-modifiers@0.1.0 test > jest FAIL specs/App.spec.js ✓ left click (32ms) ✕ right click (7ms) ✕ right click with modifier (4ms) ● right click expect(received).toBe(expected) // Object.is equality Expected: "right" Received: "click-me" 11 | const wrapper = mount(App); 12 | await wrapper.find(".btn").trigger("click", { button: 2 }); > 13 | expect(wrapper.find(".btn").text()).toBe("right"); | ^ 14 | }); 15 | 16 | at Object.<anonymous> (specs/App.spec.js:13:39) ● right click with modifier expect(received).toBe(expected) // Object.is equality Expected: "right" Received: "left" 18 | const wrapper = mount(App); 19 | await wrapper.find(".btn").trigger("click.right"); > 20 | expect(wrapper.find(".btn").text()).toBe("right"); | ^ 21 | }); 22 | at Object.<anonymous> (specs/App.spec.js:20:39) console.log src/App.vue:27 left click console.log src/App.vue:27 left click Test Suites: 1 failed, 1 total Tests: 2 failed, 1 passed, 3 total Snapshots: 0 total Time: 1.224s Ran all test suites.
Expected behaviour
The click handler should be called.
Actual behaviour
For the click.right
case the left click handler (I guess just the first handler) will be called. For the button: 2
case none of the handlers are called.
Possible Solution
Only use a single <div @click="onMouseClick">
handler and handle the buttons in the MouseEvent
object. But this affects changes in the code, not yet found a workaround that would affect test code only.