We're getting timeouts on random tests each time when CircleCI is running the tests (they all work fine locally). Usually we have to rerun the tests multiple times on CircleCI then they will eventually pass, but its starting to happen more and more and frankly becoming an annoyance.
The error given is:
Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
This is an example of a test that fails (although its really random which one fails), and ive altered some of the names as i dont wish them to be shown
describe('SomeComponent', () => {
// Mocks
const serviceOne = jasmine.createSpyObj('ServiceOne', ['getFilterByType', 'createFilter']);
const getFilterByTypeSpy = serviceOne.getFilterByType.and.returnValue(of({archived: false}));
const createFilterSpy = serviceOne.createFilter.and.returnValue(of(new ()));
const userService = {
user$: of(new User()),
remindersUpdated$: of(new User())
};
let component: SomeComponent;
let fixture: ComponentFixture<SomeComponent>;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule,
RouterTestingModule,
ToastrModule.forRoot(),
NgxPermissionsModule.forRoot(),
NgxSmartModalModule.forRoot()
],
declarations: [ SomeComponent ],
providers: [
DatePipe,
{provide: ServiceOne, useValue: serviceOne},
{provide: UserService, useValue: userService}
],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(SomeComponent);
component = fixture.componentInstance;
getFilterByTypeSpy.calls.reset();
fixture.detectChanges();
});
}));
it('should create', () => {
expect(component).toBeTruthy();
});
describe('loading pre-existing filters',
() => {
it('should call getFilterByType on init', () => {
expect(getFilterByTypeSpy).toHaveBeenCalledTimes(1);
});
it('should load in the filters into customFilter property', () => {
expect(component.customFilter).toEqual({archived: false});
});
});
describe('applying new filters',
() => {
beforeEach(() => {
createFilterSpy.calls.reset();
component.filtersApplied({archived: true});
});
it('should call createFilter', () => {
expect(createFilterSpy).toHaveBeenCalledTimes(1);
});
it('customFilter should contain archived true', () => {
expect(component.customFilter).toEqual({archived: true});
});
});
});
Is there something that i'm missing, or perhaps i'm setting the tests up incorrectly?
Thanks in advance