mardi 14 janvier 2020

How can I let Jasmine wait for a promise to be resolved or rejected?

I have a particular function that I am trying to test using Angular. This function returns a promise. Although in my test I set expectations for the promise result, Jasmine does not wait for the promises to be resolved or rejected.

Warning:

ERROR: 'Spec 'test' has no expectations.'

The tested function is defined like:

public validate(file: File): Promise<any[]> {
    return new Promise((resolve, reject) => {
      // Code
    }
}

The test code:

it(
    test.description,
    fakeAsync(() => {
      // Doesnt wait for the following promise result:
      importValidator.validate(test.testFile).then(
        resolveValue => {
          expect(Array.isArray(resolveValue)).toBe(true);
        },
        onReject => {
          expect(test.resolve).toBeFalsy();
        }
      );
    })
  );

How can I let Jasmine wait during the tests for the validation promise to be resolved/rejected? When I let the test fail by expected something not happening, it actually throws an error in the afterAll.

Aucun commentaire:

Enregistrer un commentaire