mercredi 26 septembre 2018

Jest unresolved promise do not fail

Jest docs says:

Unresolved Promises

If a promise doesn't resolve at all, this error might be thrown:

(and so on)

In my case this not happen. I have this test:

test('detect infinite loop', () => {
    expect.assertions(1);

    const vastPromise = VastUtils.parseFromUrl(infiniteLoopUrl);
    const expectedError =
        new VastError(VastErrorCodes.WRAPPER_LIMIT_REACHED);
   return expect(vastPromise).rejects.toEqual(expectedError); 
});

VastUtils simply fetch an XML located at infiniteLoopUrl, parse it, and if this xml point to another xml, VastUtils follow the link, parse the new xml, merge them and repeat the process. Now, infiniteLoopUrl point to an XML that refers itself, so it is an infinite loop. "correctly", the code follow xml link infinitely, and never resolve or reject the promise.

I expect above test fail after a certain timeout, but it didn't.

Someone can help me? Thanks

Aucun commentaire:

Enregistrer un commentaire