Feature request
What is the current behavior?
Currently, setupFiles and setupTestFrameworkScriptFile can only setup environment synchronously.
What is the expected behavior?
It would be great if it Jest would run the test _after_ awaiting any Promise that is the default export of any setupFile or setupTestFrameworkScriptFile the before running each test.
Is there anything that prevents you to await this code in beforeEach() hook?
Mostly cleanliness and DRY code. Nothing prevents me from doing a beforeEach() as that's what I'm doing now. However, I need to copy and paste the beforeEach() setup to each unit-test file. The point of setupFiles and setupTestFrameworkScriptFile is, as far as I understand, that common environment setup to all unit tests can be done in a centralized place.
We'll not be adding this for now as the complexity isn't really worth it. The recommended solution is to create a test utils file and use it like so:
const TestUtils = require('TestUtils');
beforeEach(TestUtils.setup);
OK, I understand your position. Thanks for having a look at it. 馃憤
Note that it's possible to put a beforeAll hook in your setupTestFrameworkScriptFile which avoids needing to put one in each test suite.
Oh wow, @tamlyn, it really worked for me! My god, for years I didn't know about this solution!
Most helpful comment
Note that it's possible to put a
beforeAllhook in yoursetupTestFrameworkScriptFilewhich avoids needing to put one in each test suite.