TODO 测试


¥TODO tests

通过将 todo 选项传递给测试,或通过调用测试上下文的 todo() 方法,可以将单个测试标记为不稳定或不完整,如以下示例所示。这些测试代表需要修复的待实现或错误。TODO 测试会被执行,但不会被视为测试失败,因此不会影响进程退出代码。如果测试被标记为 TODO 并被跳过,则 TODO 选项将被忽略。

¥Individual tests can be marked as flaky or incomplete by passing the todo option to the test, or by calling the test context's todo() method, as shown in the following example. These tests represent a pending implementation or bug that needs to be fixed. TODO tests are executed, but are not treated as test failures, and therefore do not affect the process exit code. If a test is marked as both TODO and skipped, the TODO option is ignored.

// The todo option is used, but no message is provided.
test('todo option', { todo: true }, (t) => {
  // This code is executed, but not treated as a failure.
  throw new Error('this does not fail the test');
});

// The todo option is used, and a message is provided.
test('todo option with message', { todo: 'this is a todo test' }, (t) => {
  // This code is executed.
});

test('todo() method', (t) => {
  t.todo();
});

test('todo() method with message', (t) => {
  t.todo('this is a todo test and is not treated as a failure');
  throw new Error('this does not fail the test');
});