← 返回 Skills 市场
anderskev

Vitest Testing

作者 Kevin Anderson · GitHub ↗ · v1.1.0 · MIT-0
cross-platform ✓ 安全检测通过
436
总下载
0
收藏
2
当前安装
1
版本数
在 OpenClaw 中安装
/install vitest-testing
功能描述
Vitest testing framework patterns and best practices. Use when writing unit tests, integration tests, configuring vitest.config, mocking with vi.mock/vi.fn,...
使用说明 (SKILL.md)

Vitest Best Practices

Quick Reference

import { describe, it, expect, beforeEach, vi } from 'vitest'

describe('feature name', () => {
  beforeEach(() => {
    vi.clearAllMocks()
  })

  it('should do something specific', () => {
    expect(actual).toBe(expected)
  })

  it.todo('planned test')
  it.skip('temporarily disabled')
  it.only('run only this during dev')
})

Common Assertions

// Equality
expect(value).toBe(42)                    // Strict (===)
expect(obj).toEqual({ a: 1 })             // Deep equality
expect(obj).toStrictEqual({ a: 1 })       // Strict deep (checks types)

// Truthiness
expect(value).toBeTruthy()
expect(value).toBeFalsy()
expect(value).toBeNull()
expect(value).toBeUndefined()

// Numbers
expect(0.1 + 0.2).toBeCloseTo(0.3)
expect(value).toBeGreaterThan(5)

// Strings/Arrays
expect(str).toMatch(/pattern/)
expect(str).toContain('substring')
expect(array).toContain(item)
expect(array).toHaveLength(3)

// Objects
expect(obj).toHaveProperty('key')
expect(obj).toHaveProperty('nested.key', 'value')
expect(obj).toMatchObject({ subset: 'of properties' })

// Exceptions
expect(() => fn()).toThrow()
expect(() => fn()).toThrow('error message')
expect(() => fn()).toThrow(/pattern/)

Async Testing

// Async/await (preferred)
it('fetches data', async () => {
  const data = await fetchData()
  expect(data).toEqual({ id: 1 })
})

// Promise matchers - ALWAYS await these
await expect(fetchData()).resolves.toEqual({ id: 1 })
await expect(fetchData()).rejects.toThrow('Error')

// Wrong - creates false positive
expect(promise).resolves.toBe(value)  // Missing await!

Quick Mock Reference

const mockFn = vi.fn()
mockFn.mockReturnValue(42)
mockFn.mockResolvedValue({ data: 'value' })

expect(mockFn).toHaveBeenCalled()
expect(mockFn).toHaveBeenCalledWith('arg1', 'arg2')
expect(mockFn).toHaveBeenCalledTimes(2)

Additional Documentation

Test Methods Quick Reference

Method Purpose
it() / test() Define test
describe() Group tests
beforeEach() / afterEach() Per-test hooks
beforeAll() / afterAll() Per-suite hooks
.skip Skip test/suite
.only Run only this
.todo Placeholder
.concurrent Parallel execution
.each([...]) Parameterized tests
安全使用建议
This skill is a set of Vitest examples and best-practice notes and appears coherent with its stated purpose. It's low-risk because it requests no credentials and has no installer, but two practical cautions: (1) provenance is unspecified (no homepage/source) — prefer content from an official or known author when security/trust matters; (2) the docs show using environment variables and setup files: do not place secrets in test env files or automatically run untrusted test setup code in CI or on machines with access to sensitive data. If you need stronger assurance, ask the publisher for a source repository or license before installing/using.
功能分析
Type: OpenClaw Skill Name: vitest-testing Version: 1.1.0 The skill bundle provides comprehensive documentation and best practices for the Vitest testing framework, including configuration, mocking, and common testing patterns. All files (SKILL.md, CONFIG.md, MOCKING.md, PATTERNS.md) contain standard, safe code examples and instructions aligned with the stated purpose. No indicators of malicious behavior, data exfiltration, or prompt injection were found.
能力评估
Purpose & Capability
Name/description match the provided files: examples, config snippets, mocking and pattern guidance for Vitest. No unrelated binaries, credentials, or third-party services are requested.
Instruction Scope
SKILL.md and companion files contain sample test code, config examples, and mocking patterns. They do not instruct reading arbitrary host files, exfiltrating data, or contacting external endpoints. They do show process.env/.env.test usage as normal examples for tests.
Install Mechanism
No install spec and no code files that would be written to disk or executed by an installer. This is instruction-only, the lowest install risk.
Credentials
The documentation shows how tests can access environment variables (process.env, .env.test and vi.stubEnv) but the skill does not declare or require any environment variables or credentials. Examples referencing env vars are expected for testing docs but users should avoid putting secrets into test env files.
Persistence & Privilege
always is false, no config paths or persistent modification of other skills or system settings. The skill is user-invocable and may be invoked by agents normally, which is expected for instructional skills.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install vitest-testing
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /vitest-testing 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.1.0
- New best practices and usage reference for Vitest testing framework. - Includes quick examples for unit/integration tests, assertions, mocking (vi.fn, vi.mock), async testing, and test metadata (skip, only, todo). - Reference tables summarize common API methods and hooks. - Links to additional documentation on mocking, configuration, and patterns. - Emphasizes correct handling of async/promise tests to avoid false positives.
元数据
Slug vitest-testing
版本 1.1.0
许可证 MIT-0
累计安装 2
当前安装数 2
历史版本数 1
常见问题

Vitest Testing 是什么?

Vitest testing framework patterns and best practices. Use when writing unit tests, integration tests, configuring vitest.config, mocking with vi.mock/vi.fn,... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 436 次。

如何安装 Vitest Testing?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install vitest-testing」即可一键安装,无需额外配置。

Vitest Testing 是免费的吗?

是的,Vitest Testing 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Vitest Testing 支持哪些平台?

Vitest Testing 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Vitest Testing?

由 Kevin Anderson(@anderskev)开发并维护,当前版本 v1.1.0。

💬 留言讨论