0

I am using Jasmin, Karma and Angular TestBed for Unit tests in Angular. I am getting an error

Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

I am using fakeAsync and tick methods. After searching, i have added timeout parameter for my tests and even given 2000 milliseconds for tick as well.

it('Should setup the initial data', fakeAsync(() => {

      fixture.detectChanges();
      tick(2000);

      expect(getUsersSpy).toHaveBeenCalledTimes(1);     

    }), 10000);


 it('Should ensure form is dirty when user changed', fakeAsync(() => {
      fixture.detectChanges();
      tick(2000);

      fixture.whenStable().then(() => {
        userComponentInstance.ngOnInit();        
        userComponentInstance.onUserChanged();
        fixture.detectChanges();        
        expect(userComponentInstance.userForm.form.dirty).toBeTruthy();
      });

 }), 10000);

No Luck with the above code. As per jasmine: Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL I have tried with but it is not working for me. I didnt choose first solution as I am working with fakeAsync and not done

var originalTimeout;

beforeEach(function() {
    originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
});

afterEach(function() {
  jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});

I have the below line in one of its child component. The child component created in a loop

ngAfterViewInit() {
    setTimeout(() => {
        jQuery("#" + this.name).selectpicker();
    },0);        
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Developer
  • 487
  • 9
  • 28
  • Please post either a [mcve] reproducing your issue, and/or your component code. –  Sep 10 '18 at 07:39
  • @trichetriche, The component which is under test is huge and it has more services and nested components integrated.I am writing integration tests. I have posted here to see, if I am doing anything wrong using fakeAsync, tick and timeout secs – Developer Sep 10 '18 at 07:43
  • How could we know you did something wrong if we don't even know what you're doing ? Post the relevant code, or as explained in the link, a **minimal** example reproducnig the issue (i.e. only the code relevant to the tests). –  Sep 10 '18 at 07:43
  • @trichetriche, I try to remove child components and see where it causes issue and update the code soon – Developer Sep 10 '18 at 07:46

0 Answers0