对于所有测试用例,在何处放置“ beforeEach”?

问题描述 投票:2回答:1

这两个测试之间有什么区别:

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...
})
javascript unit-testing mocha
1个回答
1
投票

如果将beforeEach放入描述中,则它将在此块中的每个测试之前运行。如果将其放在根级别,它将在所有测试文件中的所有测试之前运行。

请参见https://github.com/demo-drive-learn/mocha-root-pre-hook,或选中此demo

© www.soinside.com 2019 - 2024. All rights reserved.