I need to ensure that some code is executed before all tests are run.
My jest.config.js
setup:
// truncated...
setupFilesAfterEnv: [
"./jest.setup.ts"
]
The content of jest.setup.ts
:
async function setUp() {
const first = new Promise((res, rej) => {
res('this called first');
})
const second = new Promise((res, rej) => {
res('this called second');
})
first.then((firstRes) => {
console.log(firstRes)
second.then(secondRes => console.log(secondRes))
})
}
beforeAll(done => {
setUp().then(done => console.log(done));
done();
})
Upon running the tests, it appears that they are not being executed in order:
PASS packages/dao/dao.service.spec.ts (5.532 s)
Dao Tests
✓ should be defined (2 ms)
✓ get should return null
.log
Running pre-scripts for integration tests...
at Object.<anonymous> (jest.setup.ts:56:9)
.log
this called first
at jest.setup.ts:86:13
.log
undefined
at jest.setup.ts:91:32
.log
this called second
at jest.setup.ts:87:38
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 5.612 s, estimated 11 s
Ran all test suites.
The output suggests that the tests are being run before the execution of jest.setup.ts
.