vendredi 16 mars 2018

How to test the order of ASYNC Requests with Jest

I need to test that a series of asynchronous functions are called in a particular order. Is there an easy way to do this?

An example of what I want to achieve below:

describe("Test ASYNC order", () => {
    it("Calls in a particular order", () => {
        const p1 = new Promise(resolve => setTimeout(resolve, 500));
        const p2 = new Promise(resolve => setTimeout(resolve, 600));
        const p3 = new Promise(resolve => setTimeout(resolve, 200));

        /* How would I test that the order of the promises resolving is p3 then p1 then p2 ????? */
    })
})

Aucun commentaire:

Enregistrer un commentaire