describe 测试中的块没有按预期工作
describe block in test doesn't work as expected
我正在使用 mocha。
describe('test', async function () {
let a;
before(async () => {
a = 10;
})
it("ff", () => {
})
describe("nice", () => {
const b = a;
console.log(b);
it("ss", () => {
console.log("nice")
})
})
})
似乎 console.log(b)
打印未定义。即使 before
块首先执行。
知道 b
是未定义的而不是 10 吗?
describe
函数将在调用挂钩之前被调用。测试顺序 (it
) 将保留您想要的顺序。例如,在你打印 "nice"
的回调中,a
是 10.
When a test file is loaded, Mocha executes all of its suites and finds–but does not execute–any hooks and tests therein.
来源:https://mochajs.org/#serial-mode(第 8 步)
我正在使用 mocha。
describe('test', async function () {
let a;
before(async () => {
a = 10;
})
it("ff", () => {
})
describe("nice", () => {
const b = a;
console.log(b);
it("ss", () => {
console.log("nice")
})
})
})
似乎 console.log(b)
打印未定义。即使 before
块首先执行。
知道 b
是未定义的而不是 10 吗?
describe
函数将在调用挂钩之前被调用。测试顺序 (it
) 将保留您想要的顺序。例如,在你打印 "nice"
的回调中,a
是 10.
When a test file is loaded, Mocha executes all of its suites and finds–but does not execute–any hooks and tests therein.
来源:https://mochajs.org/#serial-mode(第 8 步)