期望测试失败


🌐 Expecting tests to fail

这会颠倒特定测试或测试套件的通过/失败报告:被标记的测试/测试用例必须抛出异常才能“通过”;未抛出异常的测试/测试用例则失败。

🌐 This flips the pass/fail reporting for a specific test or suite: A flagged test/test-case must throw in order to "pass"; a test/test-case that does not throw, fails.

在下文中,doTheThing() 当前 返回 falsefalse 不等于 true,导致 strictEqual 抛出异常,因此测试用例通过)。

🌐 In the following, doTheThing() returns currently false (false does not equal true, causing strictEqual to throw, so the test-case passes).

it.expectFailure('should do the thing', () => {
  assert.strictEqual(doTheThing(), true);
});

it('should do the thing', { expectFailure: true }, () => {
  assert.strictEqual(doTheThing(), true);
}); 

skip 和/或 todoexpectFailure 互斥,而 skiptodo 在同时应用时会“胜出”(skip 对两者都胜出,而 todo 胜过 expectFailure)。

这些测试将被跳过(不会运行):

🌐 These tests will be skipped (and not run):

it.expectFailure('should do the thing', { skip: true }, () => {
  assert.strictEqual(doTheThing(), true);
});

it.skip('should do the thing', { expectFailure: true }, () => {
  assert.strictEqual(doTheThing(), true);
}); 

这些测试将被标记为“待办”(忽略错误):

🌐 These tests will be marked "todo" (silencing errors):

it.expectFailure('should do the thing', { todo: true }, () => {
  assert.strictEqual(doTheThing(), true);
});

it.todo('should do the thing', { expectFailure: true }, () => {
  assert.strictEqual(doTheThing(), true);
});