4

I'm writing a series of tests against a database. All tests take the following form:

test("Name", async ()=>{
    // I do not call done(). I didn't think I had to anymore,
    // and I get type errors if I do.
});

Unfortunately, this is causing concurrency issues. I'm not sure if that's down to background tasks on the DB, or Jest running tests concurrently. The tests work fine when run individually, so I know concurrency of some sort is the problem.

How can I make absolutely sure that Jest runs these async tests one at a time?

1 Answer 1

4

In Jest, the tests in a single file run serially in the order of appearance. However, the tests in multiple files run concurrently. This is a problem when you are running all the tests against a single database.

To disable running the tests in multiple files concurrently, use the CLI option --runInBand in your jest command.

For example:

jest --runInBand

If you use scripts like npm run test to run your tests, then append the --runInBand to the associated command in package.json file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.