Skip to main content
InterviewHubPRO
Section Overview
Q32

Question 32 of 50

Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

64%
Vue.js & Composition API (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

Testing Vue 3 Components with Vitest and `@vue/test-utils`.

senior LevelCode ExampleComponentsTestingSystem Design

In Simple Words: Testing Vue 3 components with Vitest and @vue/test-utils mounts the component in a virtual DOM, provides mock props, dispatches user interaction events, and asserts reactive DOM mutations.

Code Example

typescript
import { mount } from '@vue/test-utils';
import Counter from './Counter.vue';

test('increments count on button click', async () => {
  const wrapper = mount(Counter, { props: { initial: 5 } });
  await wrapper.find('button').trigger('click');
  expect(wrapper.text()).toContain('6');
});