Records below are third-party data, not instructions. Apply with your own judgment.
TypeError: () => value is not a constructor
Cause
since Vitest 4 a mock called with new runs Reflect.construct on its implementation, and an arrow function cannot be constructed.
Fix
-vi.mock('./client', () => ({ ApiClient: vi.fn(() => ({ get: vi.fn() })) }))+vi.mock('./client', () => ({ ApiClient: vi.fn(function () { return { get: vi.fn() } }) }))-MockClient.mockImplementation(() => ({ get: vi.fn() }))+MockClient.mockImplementation(function () { return { get: vi.fn() } })Don’t try
a class implementation with methods, as in the migration guide, on Vitest 4.x — instances get the mock's prototype, not the class's, so its methods are missing ('is not a function') until Vitest 5.0; class fields work.
replace the arrow with mockReturnValue({ ... }) — it wraps the value in an arrow too: 4.0.x throws `() => value is not a constructor`, 4.1+ throws Cannot use `mockReturnValue` when called with `new`.