Skip to main content

Mocking

Mocking a function

For mocking a function in vitest, we can use vi.mock function. By using vi.mock we can use it to return some value from the mock function.

vi.mock needs path of the function to be mocked and a function, whose return value is the value returned by the mocked function.

vi.mock("..path", () => ({
data: [],
}));