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

另请参阅