【发布时间】:2020-12-11 16:40:57
【问题描述】:
我的 Express 后端中有一个 Jest 测试文件,当它包含一个 describe() 块时,它可以完美运行。但是,一旦添加了另一个描述块,无论我设置了多长时间,我都会收到此错误:
Timeout - Async callback was not invoked within the 30000ms timeout specified by jest.setTimeout.
如果我将第二个描述块添加到单独的文件中,它们都可以正常运行,并且它们的组合运行时间小于 30 秒。但是我看不出有什么理由每次我想要一个新的测试套件时都创建一个新文件。
这是两个套件的极其简化的版本:
jest.setTimeout(30000);
describe('Mealplan Model Test', () => {
beforeAll(async () => {
await db.Connection;
});
afterAll(async () => {
await mongoose.connection.close();
});
it('create & save mealPlan successfully', async (done) => {
// Test logic
});
// You shouldn't be able to add in any field that isn't defined in the schema
it('insert mealplan successfully, but the extra field does not persist', async (done) => {
// test logic
});
// etc
});
describe('Create User recipes and foods based on admin versions', () => {
let foodAdmin, recipeAdmin, user;
beforeAll(async () => {
await db.Connection;
});
afterAll(async () => {
await mongoose.connection.close();
});
it('creates user recipe based on admin recipe', async () => {
// test logic
});
it('returns the correct userRecipe if one already exists', async () => {
// test logic
});
// etc
});
【问题讨论】:
-
@Anthony 通读后,我不这么认为。在我的情况下,两个测试套件都在它们自己的情况下成功通过,所以即使失败了,测试也不会继续运行。我想要的是能够在一个测试文件中包含多个描述块并让它们都工作。如果一个失败让另一个运行也没关系。
-
如果你从
it块中的参数中删除done,你能看到会发生什么吗?
标签: javascript express mongoose jestjs