sindresorhus / ky

🌳 Tiny & elegant JavaScript HTTP client based on the Fetch API
MIT License
13.62k stars 363 forks source link

What is an example of using jest.mock("ky") with mockResolvedValue? #487

Closed srmxlt closed 1 year ago

srmxlt commented 1 year ago

import ky from "ky";

jest.mock("ky");

it("should fetch data", () => { ky.post.mockResolvedValue(() => ({ json: () => Promise.resolve(resp), })); } )

the snippet above results in an error "_ky.default.post(...).json is not a function"

The main question is: What is the correct way to use jests' mockResolvedValue with ky? I have not found any examples of this usage yet. any examples would be greatly appreciated. Thank you!