Testing User Interactions and Events
wrapper.trigger('click'), setValue(), wrapper.vm.$emit(), async flushPromises().
Simulating User Behavior
Beyond rendering, tests should mimic what a user does: clicking buttons, typing into inputs, submitting forms. @vue/test-utils wrappers expose methods to dispatch DOM events and update Vue afterward.
trigger for Click Events
wrapper.trigger("click") fires a click on the element. Because it updates the DOM, it returns a promise — await it so assertions see the result.
const button = wrapper.get("button")
await button.trigger("click")
expect(wrapper.text()).toContain("Clicked once")All lessons in this course
- Vitest Setup for Vue Projects
- Mounting and Querying Components
- Testing User Interactions and Events
- Mocking Composables, Stores, and APIs