-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle other spies by default #143
Comments
I was going to ask a similar question: is it possible to make it work with |
Not yet, but I do need to add this |
I hacked a working version to unlock our migration to vitest, and ended up with something like this (to mimick what you're currently doing): const router = createRouterMock({
createSpy: fn => {
const spy = vi.fn(fn);
return [spy, () => spy.mockClear()];
}
}); Do you imagine something like this, or maybe (haven't tried): const router = createRouterMock({
createSpy: vi.fn(),
clearSpy: spy => spy.mockClear()
}); ? I can work on a PR to add this, if you give me some guidance. Another path would be to automatically handle vitest, which would be nice, but I'm not sure this is as easily doable as for sinon or jest... |
maybe grouping spy options in an object: spy: {
create: ...
restore: ...
} To me the most interesting part is allowing a way to handle the types, probably by extending a global interface as I don't think there is a way to check for global types in TS? ( Feel free to work on this, I will come back to this in a week or two and will be able to bring any guidance too! |
I'll put together a first version that unblocks the use use of other test fwk, with a For the type checking part, I'm not sure, we'll need to try, but that might not be easy... It would be awesome to handle vitest out of the box, but unlike the others, it has to be imported (no globals AFAIK). |
We definitely don't want to make |
Refs posva#143 By default the mock will use sinon or jest support to create and restore spies. This commit adds a `spy` option that allows to use a different testing framework, by providing a method to create spies, and one to restore them. For example, with vitest: ```ts const router = createRouterMock({ spy: { create: fn => vi.fn(fn), restore: spy => () => spy.restore() } }); ```
Refs posva#143 By default the mock will use sinon or jest support to create and restore spies. This commit adds a `spy` option that allows to use a different testing framework, by providing a method to create spies, and one to restore them. For example, with vitest: ```ts const router = createRouterMock({ spy: { create: fn => vi.fn(fn), restore: spy => () => spy.restore() } }); ```
Nice! 👌 |
Published in 0.1.4. Let me know if it works. For adding automatic types for vitest I wrote this: import { createRouterMock } from 'vue-router-mock'
import { JestMockCompatFn } from 'vitest'
declare module 'vue-router-mock' {
export interface RouterMockSpy<Fn> {
spy: JestMockCompatFn<Parameters<Fn>, ReturnType<Fn>>
}
} |
The text was updated successfully, but these errors were encountered: