Skip to main content
为了提醒自己稍后编写测试,可以使用 test.todo 函数。无需提供测试实现。
https://mintcdn.com/ikxin/RzFFGbzo0-4huILA/icons/typescript.svg?fit=max&auto=format&n=RzFFGbzo0-4huILA&q=85&s=a3dffd2241f05776d3bd25171d0c5a79test.ts
import { test, expect } from "bun:test";

// 稍后编写此测试
test.todo("未实现的功能");

bun test 的输出会显示遇到了多少个 todo 测试。
terminal
bun test
test.test.ts:
✓ add [0.03ms]
✓ multiply [0.02ms]
✎ 未实现的功能

 2 通过
 1 待办
 0 失败
 2 次 expect() 调用
共运行 3 个测试,涉及 1 个文件。 [74.00ms]

也可以选择提供测试实现。
import { test, expect } from "bun:test";

test.todo("未实现的功能", () => {
  expect(Bun.isAwesome()).toBe(true);
});

如果提供了实现,除非传递了 --todo 标志,否则它不会被执行。如果传递了 --todo 标志,测试将被执行,并且测试运行器预期其失败!如果 todo 测试通过,bun test 运行将返回非零退出码以表示失败。
terminal
bun test --todo
my.test.ts:
✗ 未实现的功能
  ^ 此测试标记为todo但通过了。请移除 `.todo` 或检查测试是否正确。

 0 通过
 1 失败
 1 次 expect() 调用
$ echo $?
1 # 这是前一个命令的退出代码

另见: