'Mock useFetch hook with Jest

Im having this functional component with the useFetch hook:

function Foo(){

  const { data, isPending, run } = useFetch(`http://localhost:8080/users`);
}

How can I mock the data const here without doing an API call? The useFetch hook is from the library react-async



Solution 1:[1]

import React from "react";
import reactAsync from "react-async";

jest.mock('reactAsync');

it("test", async () => {
  const data = []
  const isPending = false
  const run = null
  reactAsync.useFetch.mockReturnValueOnce({ data, isPending, run });
});

see here for other ways

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HenriDev