dimanche 5 mai 2019

How to fail a test if a rejected promises catch?

How to fail a test if a rejected promises catch?
I'm trying to set up an angular service test to the asynchronous sign-in function. If it returns a rejected promise, handled by the catch, the test should fail. But the test always is a success.


  it('should sign-in with email and password', async(() => {

    const service: AuthService = TestBed.get(AuthService);

    // the strings can't be empty the service returns a rejected promise.
    service.signInWithEmailAndPassword('', '').then(user => {


    }).catch(error => {

        fail();
    });
  }));

the karma is throwing this Error:

ERROR: 'Unhandled Promise rejection:', ''fail' was used when there was no current spec, this could be because an asynchronous test timed out', '; Zone:', 'ProxyZone', '; Task:', 'Promise.then', '; Value:', Error: 'fail' was used when there was no current spec, this could be because an asynchronous test timed out Error: 'fail' was used when there was no current spec, this could be because an asynchronous test timed out

Aucun commentaire:

Enregistrer un commentaire