You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To test the logic, we need to mock the module failure. But vi.mock("foo-lib", () => { throw "failure" }) doesn't work. Currently, we use __mock__ file as the workaround, but it's really annoy to add the mock files which only have simple throw statement in them. And it also means we can't use __mock__ files for normal cases.
Suggested solution
Let's introduce a new API to mock module failure: vi.mockFailure(path).
I understand the options and factory could provide flexibility so you can mock a module only fails in some conditions. Our case don't need such flexibility so I only proposed a simple method, but yes, options may be a more general solution.
Clear and concise description of the problem
Some times we write the conditional logic rely on the result of dynamic import, eg.
To test the logic, we need to mock the module failure. But
vi.mock("foo-lib", () => { throw "failure" })
doesn't work. Currently, we use__mock__
file as the workaround, but it's really annoy to add the mock files which only have simplethrow
statement in them. And it also means we can't use__mock__
files for normal cases.Suggested solution
Let's introduce a new API to mock module failure:
vi.mockFailure(path)
.Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: