Reputation: 16364
I am having some problems with the order used by Jest to run tests.
Let's imagine that I have two tests:
module1.spec.ts
module2.spec.ts
Each of those modules use a common database. At the beginning of each file, I have a beforeEach
call that drops the database and recreates fresh data.
If I launch module1.spec.ts
, everything works fine. If I launch module2.spec.ts
, everything works fine.
When I try to use the jest
global command to launch all of my tests, it does not work.
My theory is that module1.spec.ts
and module2.spec.ts
are running in a different thread or at least are run kind of "at the same time".
The problem with that approach is that the two tests have to run one after the other because module1.spec.ts
and module2.spec.ts
are both dropping the database and creating data during their test.
Is it something I am missing concerning testing an application with a database?
Is their a Jest option to run the tests one after the other?
Upvotes: 3
Views: 1294
Reputation: 377
I encounterd this problem. By now my method is to export
the test cases in module1.spec.js
and module2.spec.js
, and require
them in a third file like index.spec.js
, and custom the test cases running order in index.spec.js
. I don't use --runInBand
because I want other test files run parallelly with index.spec.js
.
Upvotes: 2