0Pricing
Vue Academy · Lesson

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

  1. Vitest Setup for Vue Projects
  2. Mounting and Querying Components
  3. Testing User Interactions and Events
  4. Mocking Composables, Stores, and APIs
← Back to Vue Academy