I'm trying to run some async functions before any test in a specific file is ran. I tried doing the following:
describe('api/user', () => {
let user;
const userObj = {...};
beforeAll(async () => {
user = await new User(userObj).save(); // This is a mongoose document
});
...
});
Whenever I have something in the beforeAll
function I get an error:
Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.
I tried changing the timeout time to 30 seconds and that didn't fix it. I then tried adding the done
function before the end of the beforeAll
function, and it didn't fix the issue either.
How can I run await
in the beforeAll
function?
timeout
of thebeforeAll
function works. – Duc Nguyenthen
and return the promise – Adrian Pascunew User().save()
code is probably not runs. – felixmosh