스킬 vitest
🧪

vitest

낮은 위험 ⚡ 스크립트 포함🌐 네트워크 접근📁 파일 시스템 액세스🔑 환경 변수⚙️ 외부 명령어

使用 Vitest 編寫和執行測試

編寫和維護測試非常耗時。Vitest 提供了一個由 Vite 驅動的極速測試框架,具有 Jest 相容的 API,讓開發者能夠原生支援 ESM、TypeScript 和 JSX,開箱即用地編寫單元測試。

지원: Claude Codex Code(CC)
📊 69 적절함
1

스킬 ZIP 다운로드

2

Claude에서 업로드

설정 → 기능 → 스킬 → 스킬 업로드로 이동

3

토글을 켜고 사용 시작

테스트해 보기

"vitest" 사용 중입니다. 為加法函數編寫測試,返回兩個數字的和

예상 결과:

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

function add(a, b) {
return a + b
}

describe('add function', () => {
it('should return the sum of two numbers', () => {
expect(add(2, 3)).toBe(5)
expect(add(-1, 1)).toBe(0)
expect(add(0, 0)).toBe(0)
})
})

"vitest" 사용 중입니다. 在 Vitest 中模擬 API 呼叫

예상 결과:

import { describe, it, expect, vi } from 'vitest'
import { fetchUserData } from './api'

describe('fetchUserData', () => {
it('should return user data when API succeeds', async () => {
const mockUser = { id: 1, name: 'John' }
vi.spyOn(globalThis, 'fetch').mockResolvedValue(
new Response(JSON.stringify(mockUser), { status: 200 })
)

const result = await fetchUserData(1)
expect(result).toEqual(mockUser)
})
})

보안 감사

낮은 위험
v1 • 1/30/2026

This is a documentation skill for the legitimate Vitest testing framework. Static analysis flagged 681 potential issues in markdown documentation files, all of which are false positives. The scanner misidentifies markdown code block examples (shell commands, environment variables, HTTP URLs) as executable security issues. No malicious code patterns, credential exfiltration, or prompt injection attempts were found. The skill contains only documentation references and usage examples for a trusted open-source testing tool.

18
스캔된 파일
3,732
분석된 줄 수
11
발견 사항
1
총 감사 수
낮은 위험 문제 (6)
External Command References in Documentation
Shell command examples in markdown documentation are flagged as 'Ruby/shell backtick execution'. This is a false positive - backticks in markdown are code formatting delimiters, not executable Ruby code. The skill contains only documentation files (.md) that demonstrate test runner CLI usage patterns.
Environment Variable Documentation
References to process.env in documentation are flagged as environment access. This is a false positive - these are examples showing how to configure Vitest via environment variables, not actual secret access.
Hardcoded URLs in Documentation
Example URLs in documentation are flagged as hardcoded URLs. This is a false positive - these are example endpoints used in test configuration documentation.
Cryptography Keyword References
Mentions of cryptographic algorithms in documentation are flagged as 'weak cryptographic algorithm'. This is a false positive - these are references in test coverage and security testing documentation.
Dynamic Import Documentation
References to dynamic import() in documentation are flagged as script execution. This is a false positive - these are examples of ES module lazy loading patterns used in testing.
C2 Keyword References
Security terminology in documentation flagged as C2 keywords. This is a false positive - Vitest documentation includes security-related testing concepts.
감사자: claude

품질 점수

45
아키텍처
100
유지보수성
87
콘텐츠
31
커뮤니티
78
보안
91
사양 준수

만들 수 있는 것

編寫您的第一個單元測試

使用 test/it 函數和斷言建立基本的測試檔案,以驗證元件或函數的行為。

模擬外部依賴項

使用受控的模擬替換外部 API、模組或依賴時間的函數,以隔離被測試的單元。

設定持續整合測試

為 CI 環境配置 Vitest CLI 選項,包括覆蓋率閾值、平行執行和篩選的測試執行。

이 프롬프트를 사용해 보세요

基本測試建立
為 [函數/元件名稱] 編寫一個 Vitest 測試,該測試應該 [預期行為]。包含適當的斷言來驗證結果。
模擬依賴項
使用 vi.mock 或 vi.spyOn 編寫一個 Vitest 測試來模擬 [外部依賴項/API/模組]。模擬應該返回 [預期值] 並驗證 [預期行為]。
覆蓋率配置
配置 Vitest 為 [檔案/資料夾路徑] 使用 [V8/Istanbul] 提供者生成程式碼覆蓋率報告。將最小閾值設定為 [百分比]% 的 [陳述式/分支/函數/行數]。
進階測試模式
為 [功能] 編寫一個 Vitest 測試套件,使用 [beforeEach/afterAll/aroundEach] 鉤子、[concurrent] 執行和 [test.extend] 自定義固定架構。包含對 [邊緣情況] 的測試。

모범 사례

  • 使用 describe 區塊按功能或元件組織測試,將相關測試分組在一起
  • 保持測試獨立和隔離 - 避免使用 beforeEach 進行清理時在測試之間共用狀態
  • 撰寫有意義的測試描述,說明正在驗證的行為,而不僅僅是正在測試的內容

피하기

  • 避免測試實作細節 - 專注於可觀察的行為和輸出,而非內部狀態
  • 不要在沒有明確理由的情況下跳過測試 - 跳過的測試會造成技術債務並隱藏潛在問題
  • 避免過於寬鬆的斷言,這些斷言可能因多種原因通過 - 使用特定的匹配器如 toEqual 而不是 truthy 檢查

자주 묻는 질문

Vitest 與 Jest 有什麼不同?
Vitest 使用 Vite 的轉譯管線來實現更快的類似 HMR 的測試更新,無需配置即可原生支援 ESM,並與您的 Vite 應用程式共用相同的配置和外掛。它提供 Jest 相容的 API 以便輕鬆遷移。
我需要单独安裝 Vitest 嗎?
是的,此技能提供使用 Vitest 的文件和指導。您的專案必須將 Vitest 安裝為開發依賴項,並在 vite.config.ts 或 vitest.config.ts 檔案中配置。
我可以在 JavaScript 專案中使用 Vitest 嗎?
是的,Vitest 適用於 JavaScript、TypeScript、JSX 和 Vue/React/Svelte 元件。JavaScript 專案不需要 TypeScript 配置。
如何在監控模式下執行測試?
執行 'vitest' 不加參數或使用 'vitest watch' 進入監控模式。檔案變更時測試將重新執行。使用 'vitest run' 執行單次執行而不進入監控模式。
Vitest 支援哪些測試環境?
Vitest 支援 'node' 用於 Node.js ���試、'jsdom' 用於瀏覽器 DOM 模擬,以及 'happy-dom' 作為更輕量的替代方案。透過 vitest.config 中的環境選項進行配置。
如何配置覆蓋率閾值?
在 vitest.config.ts 中添加覆蓋率配置,將 coverage.provider 設定為 'v8' 或 'istanbul',然後為陳述式、分支、函數和行數指定閾值。