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` 標誌,測試將被執行並被測試執行器“預期失敗”!如果待辦測試透過,`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

另請參閱