Jest beforeAll() share between multiple test files

If you’re using Jest >=20, you might want to look into creating a custom jest-environment for the tests that require this common setup. This would be a module that extends either jest-environment-node or jest-environment-jsdom, and implements async setup(), async teardown(), and async runScript() to do this setup work.

You can then add a @jest-environment my-custom-env directive to those files that require this setup.

See the Jest config docs for testEnvironment for details on how to set this up; there’s a simple example there.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)