首页 > 解决方案 > 将所有测试用例的“beforeEach”放在哪里?

问题描述

这两个测试有什么区别:

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...
})

标签: javascriptunit-testingmocha.js

解决方案


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

请参阅https://github.com/demo-drive-learn/mocha-root-pre-hook或查看此演示


推荐阅读