Jest: Global beforeAll / Execute some code only once before ALL test files

Created on 29 Sep 2017  路  7Comments  路  Source: facebook/jest


Do you want to request a feature or report a bug?
feature

What is the current behavior?
Unable to execute some code only once before all test files, e. g. create a database, promisify functions, import reflect-metadata, etc.

What is the expected behavior?
Able to execute some before all test files.

Most helpful comment

All 7 comments

beforeEach or using your own custom test environment will work. There is a PR to make that async, #4506.

@cpojer I can't find out how your response related to the issue.

@Deilan , I'm experiencing the same thing, is there any solution run beforeAll that runs only once even if im using multiple test files?

@SimenB is there an example of how globalSetup can be used?

@thymikee, thanks! Is there a way I can use ES6 imports in the globalSetup script or in scripts it requires?

Nope, only with babel-register if you fancy

Was this page helpful?
0 / 5 - 0 ratings

Related issues

withinboredom picture withinboredom  路  3Comments

gustavjf picture gustavjf  路  3Comments

samzhang111 picture samzhang111  路  3Comments

ianp picture ianp  路  3Comments

paularmstrong picture paularmstrong  路  3Comments