Jest states in docs: "Jest virtualizes JavaScript environments and runs tests in parallel across worker processes."
But what about multiple tests inside one file, do they run in parallel or this statement applies just to the test files? Can I assume that tests in one file run in order of appearance and in serial?
Yes, you can safely assume tests inside a single file will run in the order of appearance. You could prove this by putting a
console.log
in eachit
block.It's probably worth mentioning that it's generally bad practice to rely on the order of execution / external state...and you never know, Jest (or the current underlying test runner, Jasmine) may decide to run them in a random order in a newer version.