这两个测试之间有什么区别:
beforeEach(doSomething)
describe("i am the only root describe in this test file", () => {
// many test cases...
})
describe("i am the only root describe in this test file", () => {
beforeEach(doSomething)
// many test cases...
})
如果将beforeEach
放入描述中,则它将在此块中的每个测试之前运行。如果将其放在根级别,它将在所有测试文件中的所有测试之前运行。
请参见https://github.com/demo-drive-learn/mocha-root-pre-hook,或选中此demo。