Just like the title says. Do before
/after
/beforeEach
/afterEach
hooks in Mocha work even if tests fail?
问问题
655 次
1 回答
1
是的,即使测试失败,它们也会运行。但是,如果您使用 bail 选项运行 Mocha,则拆解挂钩将不会运行。
只是在这里对现有的测试套件进行了快速检查。
编码:
setup(function() {
console.log("1");
});
teardown(function() {
console.log("2");
});
处决:
D:\Dev\JS\toposort>mocha
Toposort
◦ should sort correctly: 1
√ should sort correctly
2
◦ should find cyclic dependencies: 1
1) should find cyclic dependencies
2
◦ #2 - should add the item if an empty array of dependencies is passed: 1
√ #2 - should add the item if an empty array of dependencies is passed
2
2 passing (15 ms)
1 failing
1) Toposort should find cyclic dependencies:
AssertionError: expected [Function] to not throw 'Error' but [Error: Cyclic dependency found. '3' is dependent of itself
.] was thrown
D:\Dev\JS\toposort>mocha --bail
Toposort
◦ should sort correctly: 1
√ should sort correctly
2
◦ should find cyclic dependencies: 1
1) should find cyclic dependencies
1 passing (14 ms)
1 failing
1) Toposort should find cyclic dependencies:
AssertionError: expected [Function] to not throw 'Error' but [Error: Cyclic dependency found. '3' is dependent of itself
.] was thrown
于 2013-07-25T21:15:52.507 回答