create-utility-tests
Guide for creating utility tests in this project using Nuxt test utils and component mounting.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guide for creating utility tests in this project using Nuxt test utils and component mounting.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Workflow for creating SSR-safe, memory-safe, version-adaptive composables wrapping anime.js utilities.
Create complete documentation sites for projects. Use when asked to: "create docs", "add documentation", "setup docs site", "generate docs", "document my project", "write docs", "initialize documentation", "add a docs folder", "create a docs website". Generates Docus-based sites with search, dark mode, MCP server, and llms.txt integration.
Guide for creating pages in the playground for the module
Scaffolds a documentation sample for a new composable using the project's standard structure.
Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.
| name | Create Utility Tests |
| description | Guide for creating utility tests in this project using Nuxt test utils and component mounting. |
Tests are organized into projects within vitest.config.ts. The suites project is specifically configured for Nuxt utilities.
test/suites/utilities/ and you can add them under their own directory.Do not use mocks for DOM elements or Vue instances. Instead, use real components.
Create a Test Component: Create a .vue file (e.g., test-component.vue) in the test suite directory if the utility works with vue components or template refs
<script setup lang="ts"> and useTemplateRef for type-safe refs.defineExpose any refs needed for testing.<script setup lang="ts">
import { useTemplateRef } from 'vue'
const myRef = useTemplateRef('myRef')
defineExpose({ myRef })
</script>
<template>
<div ref="myRef"></div>
</template>
Mount the component using with mountSuspended
import { mountSuspended } from '@nuxt/test-utils/runtime'
import TestComponent from './test-component.vue'
const wrapper = await mountSuspended(TestComponent)
// Access exposed refs via wrapper.vm, casting to the Component instance type if needed
const vm = wrapper.vm
The project enforces strict TypeScript. Avoid any.
wrapper.element or find(), cast to the specific DOM type.
const div = wrapper.find('.target').element as HTMLElement
const svg = wrapper.find('svg').element as SVGElement
If testing multiple functions with similar signatures (e.g., variations of a utility), use a data-driven approach to share common tests.
const variants = [
{ name: 'variantA', fn: funcA },
{ name: 'variantB', fn: funcB }
]
describe('Common Behavior', () => {
variants.forEach(({ name, fn }) => {
describe(name, () => {
// Shared tests
})
})
})
Create separate describe blocks for behaviors unique to specific functions or edge cases.
describe('funcA (Specific)', () => {
it('should handle edge case X', () => { ... })
})
vi.mock('vue'), vi.mock('#imports').#imports or relative paths to src/runtime.any casts.vi.mock for DOM/Vue basics.mountSuspended..vue component with useTemplateRef and defineExpose.