0

Here is the method in the service that I want to test

public loadConfigurations():Promise <any> {
      return this.http.get(environment.BASE_URL).toPromise()
}

In the test.spec.ts

it('Should be return the enviroment configs from rest api',done =>{

          service.loadConfigurations().then((data)=>{
            console.log('data',data)
            expect(data).toBe('test')
            done();
          }).catch((err)=>{
            console.log(err);
          })

  })

I am getting the

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

When I run the tests without the above case, there is no timeout error so i belive something messed-up in my service

karma config

    captureTimeout: 210000,
    browserDisconnectTolerance: 3,
    browserDisconnectTimeout: 210000,
    browserNoActivityTimeout: 210000,
shamon shamsudeen
  • 5,466
  • 17
  • 64
  • 129
  • 1
    Don't wrap an existing promise in a new promise (it doesn't solve your issue but it needs to be pointed out). https://stackoverflow.com/questions/23803743/what-is-the-explicit-promise-construction-antipattern-and-how-do-i-avoid-it – Lennholm Oct 11 '19 at 10:50
  • Thanks, @Lennholm i've updated with proper with proper pattern – shamon shamsudeen Oct 11 '19 at 11:54
  • I can't see anything obviously wrong in your code. Are you getting any other error? I'm thinking the timeout might simply be secondary, a consequence of never reaching the `done()` call because the test fails before that point. – Lennholm Oct 11 '19 at 13:05
  • No errors one thing i have noticed is the code in the `then` is not reachable – shamon shamsudeen Oct 11 '19 at 18:11

0 Answers0