by Angular Developers @ Selleo

Michal Pierzchala’s jest-preset-angular makes Angular tests faster with Jest. Here is how you can make them even faster with setupTestBed :-)

Following official guide you define TestBed.configureTestingModule inside beforeEach and get the testing module reseted on each it block in the file. This is expensive, especially if you have many dependencies.

You can avoid it with beforeAll and afterAll using Brad Chen setupTestBed helper function. In our case we got tests run 3.5x times faster. People reported 8x and more speed up.

You achieve the best results if you combine it with Shallow component tests with NO_ERRORS_SCHEMA

Here is how you can setup it with jest-preset-angular. Import setupTestBed.ts in jest.setup.ts

and create index.d.ts