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

Always recreate mocks inside of setup-mocks #28

Merged
merged 1 commit into from
May 25, 2023
Merged

Conversation

jo-sm
Copy link
Contributor

@jo-sm jo-sm commented May 24, 2023

This PR fixes a setup-mocks bug which caused the bindings to not always be recreated for each test case, instead only being created once and being reused. This allows setup-mocks to be used in cases where something stateful is being mocked, such as a JS class instance.

…test case in scope

- Commit correct version for `package-lock.json` since I forgot before
@jo-sm jo-sm requested a review from ottonascarella May 25, 2023 09:35
@jo-sm jo-sm merged commit ae2a3a8 into master May 25, 2023
@jo-sm jo-sm deleted the fix-setup-mocks branch May 25, 2023 10:41
jo-sm added a commit that referenced this pull request Jun 19, 2023
A regression was caused by #28, such that the original binding values
would be called when put back (due to the change to always reinstantiate
the mocks for each test case). This wasn't covered by the tests and for
non-side-effecting functions, this wouldn't surface, but for non-functions
and for side-effecting functions, calling the original function could
cause issues.

This commit fixes that by wrapping the original binding values in functions
just like the mocks.

This commit also adds some useful comments and renames binding symbols since
every time I look at `with-scoped-redefs` I get confused since the function
was basically copied from `with-redefs`, and the naming there is a bit terse.

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

Successfully merging this pull request may close these issues.

2 participants