我有以下測驗設定:
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塊允許您確定測驗設定的范圍,以便它僅針對該特定塊內的測驗運行。
uj5u.com熱心網友回復:
似乎這是標準和記錄的行為:
Jest 在執行任何實際測驗之前執行測驗檔案中的所有描述處理程式。這是在 before* 和 after* 處理程式內部而不是在 describe 塊內部進行設定和拆卸的另一個原因。一旦描述塊完成,默認情況下,Jest 按照它們在收集階段遇到的順序依次運行所有測驗,等待每個測驗完成并在繼續之前進行整理。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/431365.html
標籤:javascript 节点.js 智能理念 开玩笑的
