-
I'm trying to mock the Lodash function
When I run a test of the component that uses
I see Lodash uses a default export, so I also tried:
That gives the same error. What is the right way to mock individual Lodash functions? As a side question, when I set up the typing as recommended in the docs ( |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
vi.mock("lodash", async (importOriginal) => {
const actual = (await importOriginal()) as any;
return {
...actual.default,
debounce: fn => fn,
default: { ...actual.default, debounce: fn => fn },
};
}); Can you setup a reproduction based on https://github.com/vitest-dev/vitest/tree/main/examples, so we can check what you're doing exactly? |
Beta Was this translation helpful? Give feedback.
Thanks, I was importing as
import { debounce } from "lodash"
(under the impression that lodash supports ESM, not sure why that works), but it looks like it won't until version 5 and using lodash-es still the recommended way to do it.Using
import { debounce } from "lodash"
, I was able to get it working using:Switching to
import { debounce } from "lodash-es"
, I was able to get it working using: