Skip to content
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

feat: create and restore spies with other test frameworks #144

Merged
merged 5 commits into from
Jan 21, 2022

Conversation

cexbrayat
Copy link
Contributor

Refs #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:

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()
  }
});
```
@posva
Copy link
Owner

posva commented Jan 21, 2022

I'm doing a few changes to this and pushing a new version so I can release a new version with the feature.
One of the changes I needed is to add a reset option for spy to reset the history of the spy instead of restoring it. It's called by the routerMock.reset() function.

Thanks a lot for the work in this!

@posva posva linked an issue Jan 21, 2022 that may be closed by this pull request
@posva posva merged commit b7fd685 into posva:main Jan 21, 2022
@cexbrayat
Copy link
Contributor Author

cexbrayat commented Jan 21, 2022

So you added reset but now restore is not used right?
The comments also need to be updated

@posva
Copy link
Owner

posva commented Jan 21, 2022

Yes, I guess I did it a bit too quickly 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle other spies by default
2 participants