rules/vue/testing.md
This file extends common/testing.md with Vue specific content.
@vue/test-utils. create-vue scaffolds @vitejs/plugin-vue.happy-dom or jsdom, set in vite.config.ts under test.environment.mount for a full render. shallowMount to stub all child components.trigger and setValue return promises, await them.flushPromises flushes resolved promise handlers. nextTick settles the DOM after a state change.inject must be tested through a host component.createTestingPinia() from @pinia/testing, passed via global.plugins. Actions are stubbed by default, set stubActions: false to run them. createSpy: vi.fn is required under Vitest (no Jest globals).beforeEach(() => setActivePinia(createPinia())) gives a fresh store per test and prevents state leakage.global.plugins, global.stubs (stubs Transition / TransitionGroup by default), global.mocks (e.g. $router), global.provide (for inject, Symbol keys supported).RouterLinkStub stubs router-link without mounting a full router.const wrapper = mount(AuctionCard, {
props: { id: 1 },
global: { plugins: [createTestingPinia({ createSpy: vi.fn })] },
})
await wrapper.find('button').trigger('click')
expect(wrapper.emitted('bid')).toBeTruthy()
frontend-patterns, vite-patterns.