Bun

指南測試執行器

使用 Bun 測試執行器將測試標記為「待辦事項」

為了提醒您稍後編寫測試,請使用 test.todo 函數。 無需提供測試實作。

import { test, expect } from "bun:test";

// write this later
test.todo("unimplemented feature");

bun test 的輸出會指示遇到多少個 todo 測試。

bun test

test.test.ts:
✓ add [0.03ms]
✓ multiply [0.02ms]
✎ unimplemented feature

 2 pass
 1 todo
 0 fail
 2 expect() calls
Ran 3 tests across 1 files. [74.00ms]

或者,您可以選擇性地提供測試實作。

import { test, expect } from "bun:test";

test.todo("unimplemented feature", () => {
  expect(Bun.isAwesome()).toBe(true);
});

如果提供了實作,則除非傳遞 --todo 標誌,否則不會執行。 如果傳遞了 --todo 標誌,測試將會執行,並且測試執行器 *預期會失敗*! 如果 todo 測試通過,bun test 執行將會傳回非零退出代碼以表示失敗。

bun test --todo
my.test.ts:
✗ unimplemented feature
  ^ this test is marked as todo but passes. Remove `.todo` or check that test is correct.

 0 pass
 1 fail
 1 expect() calls
echo $?
1 # this is the exit code of the previous command

另請參閱