測試過濾
過濾、逾時、套件和測試的並行
CLI
你可以使用 CLI 根據名稱過濾測試檔案
bash
$ vitest basic
將只執行包含 basic
的測試檔案,例如
basic.test.ts
basic-foo.test.ts
basic/foo.test.ts
你也可以使用 -t, --testNamePattern <pattern>
選項根據完整名稱過濾測試。當你想要根據檔案內定義的名稱,而非檔案名稱本身過濾時,這會很有幫助。
指定逾時
您可選擇將逾時(以毫秒為單位)傳遞為測試的第三個引數。預設為 5 秒。
ts
import { } from 'vitest'
('name', async () => { /* ... */ }, 1000)
掛勾也可以接收逾時,預設同樣為 5 秒。
ts
import { } from 'vitest'
(async () => { /* ... */ }, 1000)
略過套件和測試
使用 .skip
來避免執行某些套件或測試
ts
import { , , } from 'vitest'
.('skipped suite', () => {
('test', () => {
// Suite skipped, no error
.(.(4), 3)
})
})
('suite', () => {
.('skipped test', () => {
// Test skipped, no error
.(.(4), 3)
})
})
選取要執行的套件和測試
使用 .only
來只執行某些套件或測試
ts
import { , , } from 'vitest'
// Only this suite (and others marked with only) are run
.('suite', () => {
('test', () => {
.(.(4), 3)
})
})
('another suite', () => {
('skipped test', () => {
// Test skipped, as tests are running in Only mode
.(.(4), 3)
})
.('test', () => {
// Only this test (and others marked with only) are run
.(.(4), 2)
})
})
未實作的套件和測試
使用 .todo
來建立應該實作的套件和測試的 stub
ts
import { , } from 'vitest'
// An entry will be shown in the report for this suite
.('unimplemented suite')
// An entry will be shown in the report for this test
('suite', () => {
.('unimplemented test')
})