vue-test-utils-skilld
БесплатноБез исполняемых скриптовНе проверенALWAYS use when writing, debugging, or reviewing code that imports "@vue/test-utils" or mentions vue test-utils, VTU, mount, shallowMount, findComponent…
от skilld-dev★ 188 звёзд на GitHubОб этом скилле
@vue/test-utils 2.5.1 (Vue 3)
Prepared source: input/source, version 2.5.1 (package.json:3).
Requires Vue 3.x and @vue/compiler-dom 3.x as peers; @vue/server-renderer 3.x is an optional peer needed only for renderToString (package.json:73-81).
Test-runner agnostic (Vitest, Jest, others). Needs a browser-like DOM environment (jsdom or happy-dom).
Install: npm install @vue/test-utils --save-dev
Quick start
import { mount } from '@vue/test-utils'
import Counter from './Counter.vue'
test('increments', async () => {
const wrapper = mount(Counter, { props: { start: 1 } })
await wrapper.find('button').trigger('click')
expect(wrapper.text()).toContain('2')
})
Public API surface
Exports from dist/src/index.d.ts:13:
| Export | Kind | Use |
|---|---|---|
mount |
function | Mount a component, returns VueWrapper (dist/src/mount.d.ts:17) |
shallowMount |
function | Same as mount with all child components stubbed (dist/src/mount.d.ts:22) |
renderToString |
function | SSR-render a component to a string, Promise<string> (dist/src/renderToString.d.ts:4) |
flushPromises |
function | Await pending non-Vue promises (mocked API calls, timers) (dist/src/utils/flushPromises.d.ts:1) |
enableAutoUnmount(hook) |
function | Unmount all wrappers via a test hook (dist/src/utils/autoUnmount.d.ts:4) |
disableAutoUnmount |
function | Stop auto unmounting (dist/src/utils/autoUnmount.d.ts:3) |
VueWrapper |
class | Wrapper around a mounted component instance (dist/src/vueWrapper.d.ts:5) |
DOMWrapper |
class | Wrapper around a DOM element; new DOMWrapper(document.body) (dist/src/domWrapper.d.ts:4) |
RouterLinkStub |
component | Stub for <router-link> (dist/src/components/RouterLinkStub.d.ts:1) |
config |
object | Shared default mount options and wrapper plugins (dist/src/config.d.ts:32) |
createWrapperError |
function | Internal; produces the error wrapper returned by find misses |
Core rules
awaitevery method that returns a promise:trigger,setValue,setProps,setData,renderToString,flushPromises. Withoutawait, assertions run before the DOM updates.- Use
get()/getComponent()when the element must exist; they throw on miss. Usefind()/findComponent()only when absence is a valid outcome; they return an error wrapper whoseexists()isfalse. find()accepts CSS selectors only. To locate a child component usefindComponent(Component),findComponent({ name: 'Foo' }),findComponent({ ref: 'foo' }), or a CSS selector.- Register
enableAutoUnmount(afterEach)once in test setup to prevent state leaks between tests. - Use
flushPromises()for promises Vue does not track (mocked HTTP clients,setTimeout). wrapper.vmonly reliably exposes what the component exposes: options-API state,defineExpose()bindings (since 2.5.0, PR #2927), orsetup()return values.
import { enableAutoUnmount } from '@vue/test-utils'
import { afterEach } from 'vitest'
enableAutoUnmount(afterEach)
Version notes: 2.4.10 -> 2.5.1
- BREAKING (2.5.0): class component support removed. Mount Vue components defined with
defineComponent, options objects, or<script setup>SFCs. https://github.com/vuejs/test-utils/releases/tag/v2.5.0 - Fix (2.5.0):
emitted()history of child components is cleared when they unmount. Assert events before unmounting. https://github.com/vuejs/test-utils/pull/2898 - Fix (2.5.0):
defineExposebindings are visible onfindComponent(...).vm. https://github.com/vuejs/test-utils/pull/2927 - Fix (2.4.11):
setData()works correctly for components mixingsetup()anddata(). https://github.com/vuejs/test-utils/releases/tag/v2.4.11 - Fix (2.4.11):
trigger('keydown')sets a spec-compliantevent.code. https://github.com/vuejs/test-utils/pull/2850 - Type (2.4.11):
GlobalMountOptionsis exported. https://github.com/vuejs/test-utils/pull/2851
Earlier v2 milestones still relevant
renderToStringadded in 2.3.0 for SSR testing. https://github.com/vuejs/test-utils/releases/tag/v2.3.0html({ raw: true }), directive stubs (vName: true), and arraysetValuefor multiselect added in 2.2.0. https://github.com/vuejs/test-utils/releases/tag/v2.2.0enableAutoUnmount/disableAutoUnmountreplaced v1enableAutoDestroy. https://github.com/vuejs/test-utils/releases/tag/v2.0.0-rc.16propsDatastill works but is deprecated; useprops(dist/src/types.d.ts:33-35).stubsaccepts a record ({ Foo: true }) or an array of names (['Foo']) (dist/src/types.d.ts:80).
Migrating from v1 (Vue 2)
Full table: migration reference, official guide https://test-utils.vuejs.org/migration/
propsData->props;createLocalVueremoved ->global.plugins/global.mixinsmocks,stubs,provide,directivesmoved underglobaldestroy()->unmount();findAll().at(i)->findAll()[i](ret
Установить vue-test-utils-skilld в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл vue-test-utils-skilld?
ALWAYS use when writing, debugging, or reviewing code that imports "@vue/test-utils" or mentions vue test-utils, VTU, mount, shallowMount, findComponent, wrapper queries, or migrating from Vue Test Utils v1. Provides the current API surface, mounting options, wrapper methods, and testing recipes for @vue/test-utils 2.5.1 on Vue 3.
Как установить скилл vue-test-utils-skilld?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл vue-test-utils-skilld запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic