The problem was the app initialization was called inside a Jest's beforeAll hook, instead of a beforeEach one. As tests run in parallel, the mocked networkService instance was shared among all the tests, and even though jest.resetAllMocks() was called on the beforeEach hook, the networkService mock behaviour was sometimes unexpected due to race conditions between tests' executions.
Changes
Ensures the app initialization is called inside a Jest's beforeEach hook, instead of a beforeAll one.
Summary
This PR fixes a flaky test affecting
get-creation-transaction.transactions.controller.spec
.An example of an error in this test can be seen in the following CI run: https://github.com/safe-global/safe-client-gateway/actions/runs/11724359558/job/32658109820
The problem was the
app
initialization was called inside a Jest'sbeforeAll
hook, instead of abeforeEach
one. As tests run in parallel, the mockednetworkService
instance was shared among all the tests, and even thoughjest.resetAllMocks()
was called on thebeforeEach
hook, thenetworkService
mock behaviour was sometimes unexpected due to race conditions between tests' executions.Changes
app
initialization is called inside a Jest'sbeforeEach
hook, instead of abeforeAll
one.