在其他 describe 块中执行代码 - jest
Execution of code in other describe blocks - jest
我有以下测试设置:
describe(`my tests`, () => {
describe(`Should not run`, () => {
console.log(`Should not be printed`);
describe(`Should also not run`, () => {
console.log(`Should also not be printed`);
test(`Then an exception is thrown`, () => {
console.log(`Should definitely not be printed`);
throw new Error(`whoops`);
})
})
describe(`Should run`, () => {
console.log(`Should run`)
test(`Then I should get this list in the format I expect`, () => {
console.log(`Should definitely be printed`);
})
})
describe(`Should not run`, () => {
console.log(`Should not be printed`);
test(`Then I should get an empty list`, () => {
throw new Error(`whoops`);
})
})
})
})
当我要求 IntelliJ 仅 运行 测试用例 test('Then I should get this list in the format I expect')
时,我仍然得到以下输出:
> Should not be printed
> Should also not be printed
> Should run
> Should not be printed
> Should definitely be printed
怎么其他describe
块的代码被执行了?我认为 describe
块允许您限定测试设置的范围,以便它仅 运行s 用于该特定块内的测试。
好像是standard and documented behaviour:
Jest executes all describe handlers in a test file before it executes any of the actual tests. This is another reason to do setup and teardown inside before* and after* handlers rather than inside the describe blocks. Once the describe blocks are complete, by default Jest runs all the tests serially in the order they were encountered in the collection phase, waiting for each to finish and be tidied up before moving on.
我有以下测试设置:
describe(`my tests`, () => {
describe(`Should not run`, () => {
console.log(`Should not be printed`);
describe(`Should also not run`, () => {
console.log(`Should also not be printed`);
test(`Then an exception is thrown`, () => {
console.log(`Should definitely not be printed`);
throw new Error(`whoops`);
})
})
describe(`Should run`, () => {
console.log(`Should run`)
test(`Then I should get this list in the format I expect`, () => {
console.log(`Should definitely be printed`);
})
})
describe(`Should not run`, () => {
console.log(`Should not be printed`);
test(`Then I should get an empty list`, () => {
throw new Error(`whoops`);
})
})
})
})
当我要求 IntelliJ 仅 运行 测试用例 test('Then I should get this list in the format I expect')
时,我仍然得到以下输出:
> Should not be printed
> Should also not be printed
> Should run
> Should not be printed
> Should definitely be printed
怎么其他describe
块的代码被执行了?我认为 describe
块允许您限定测试设置的范围,以便它仅 运行s 用于该特定块内的测试。
好像是standard and documented behaviour:
Jest executes all describe handlers in a test file before it executes any of the actual tests. This is another reason to do setup and teardown inside before* and after* handlers rather than inside the describe blocks. Once the describe blocks are complete, by default Jest runs all the tests serially in the order they were encountered in the collection phase, waiting for each to finish and be tidied up before moving on.