How do you test emitted events using Vue Test Utils?
Tests Vue Test Utils event inspection. Strong answer: mount, trigger('click'), then check wrapper.emitted('increment') for the payload array. Remember it returns an array of arrays, one per emission.
What's really being asked
This question probes whether you treat components as black boxes and verify their public contract. In Vue, parent-child communication happens through props down and events up. The interviewer wants to see that you know how to simulate user interaction and then inspect the emitted event log rather than checking internal state. It also checks if you understand the specific shape of the data structure returned by wrapper.emitted().
The full answer
First, mount the component with mount(). Second, find the target element using wrapper.find() and simulate the user action with trigger('click'). Third, retrieve the event history. Calling wrapper.emitted() with no arguments returns an object where keys are event names and values are arrays of payload arrays. Calling wrapper.emitted('increment') filters to just that event and returns an array of arrays. Fourth, assert on the length of that array if the button was clicked multiple times. Fifth, assert on the contents of the inner arrays because each entry represents one emission and each argument passed to emit becomes an element in that inner array.
The mistakes people make
A major red flag is importing the component method and calling it directly, which skips the template and defeats the purpose of a component test. Another mistake is asserting on wrapper.vm.count or internal refs instead of wrapper.emitted(); this leaks into implementation details and makes tests brittle. Some candidates also forget that emitted('increment') returns an array of arrays, so they write expect(wrapper.emitted('increment')).toEqual([1]) instead of expect(wrapper.emitted('increment')[0]).toEqual([1]). Finally, failing to await next tick or using trigger incorrectly can lead to false negatives.
What usually comes next
The interviewer might ask how you would test an event emitted from a deeply nested child component, which leads to discussing emitted() on the parent wrapper or using stubbed children. They could also ask how to test v-model, which relies on update:modelValue events. Another angle is testing async event handlers where you must wait for promises to resolve before checking emitted(). They might also ask how you verify no event was emitted, which is done by checking that wrapper.emitted('increment') is undefined.
A concrete example
Suppose a Counter component emits an increment event with the current count. After two clicks, wrapper.emitted('increment') returns [ [1], [2] ]. To verify the first click, you write expect(wrapper.emitted('increment')[0]).toEqual([1]). To verify the second, expect(wrapper.emitted('increment')[1]).toEqual([2]). If the payload were an object like { count: 1, isEven: false }, the inner array would contain that object: expect(wrapper.emitted('increment')[0]).toEqual([{ count: 1, isEven: false }]).
Interview question
After two clicks emit 'increment' with values 1 and 2, which assertion correctly checks both payloads?
- a.expect(wrapper.emitted('increment')).toEqual([1, 2])
- b.expect(wrapper.emitted('increment')[0]).toEqual(1)
- c.expect(wrapper.emitted('increment')).toEqual([[1], [2]])Correct
- d.expect(wrapper.emitted()).toEqual({ increment: [1, 2] })
Why? this is the answer
wrapper.emitted('increment') returns an array of arrays, with one inner array per emission, so [[1], [2]] matches the actual structure. Option A is tempting but wrong because it flattens the payloads, forgetting that each emission wraps its arguments in an array.
Just read this? Test yourself on what you have been reading.
Read the original → test-utils.vuejs.org
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on vue — each one lists the topics its interview covers.
See open roles