jeudi 25 février 2021

mockResolvedValueOnce return promise intead of given value

import products from "services/products";

jest.mock("services/products", () => {
    return {
        getProducts: jest
            .fn()
            .mockImplementation(() => Promise.resolve([product, product])),
    };
});

((products.getProducts as unknown) as jest.Mock).mockResolvedValueOnce([product, product]);

Why is this array of [product, product] when it gets to the code it's Promise {[product, product]}
And as a result i recive an error on that array map (array.map is not a function)

Aucun commentaire:

Enregistrer un commentaire