We are using jest 27 for our project in Angular 12 for running our unit tests. Locally, these tests run correctly but runnig them in a cloud agent pipe they break, appearing this error:
thrown: "Exceeded timeout of 5000 ms for a hook. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
This is the part of code that breaks:
const createHost = createHostFactory({
component: Component,
imports: [
TranslateModule.forRoot(),
GridModule,
MaterialWrapperTestingModule,
ReactiveFormsModule,
TooltipModule,
TableEditionToolbarModule,
],
providers: [
{ provide: ContactsService, useValue: contactsServiceSpy },
{ provide: CustomerService, useValue: customerServiceSpy },
{ provide: CustomerDetailFacade, useValue: customerFacadeSpy },
{ provide: HeaderMenuFacade, useValue: headerMenuFacadeSpy },
{ provide: ContextFacade, useValue: contextFacadeSpy },
{ provide: MatDialog, useValue: dialogMock },
],});
beforeEach(() => {
host = createHost('<component-selector></component-selector>', { detectChanges: true,
props: { structure } });
return host.fixture.whenStable();
});
It takes too much time to run the tests and the task fails.
We have done several changes in order to solve it, but nothing helps:
- We have use already jest.setTimeout(newTimeout)
- We have alse used --runInBand to run tests serially