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

Consolidate mocks #1119

Merged
merged 1 commit into from
Jan 4, 2024
Merged

Consolidate mocks #1119

merged 1 commit into from
Jan 4, 2024

Conversation

scott-rc
Copy link
Collaborator

@scott-rc scott-rc commented Dec 27, 2023

I've spent a lot of time debugging issues with mocked functions due to:

  • mocking a function that's already been mocked and not knowing which implementation is being called
  • typescript not realizing a function is already mocked and having to cast it

I discovered the vitest-mock-process package a while back and ended up using a helper function it exports called spyOnImplementing a lot. spyOnImplementing has a nicer api than vi.spyOn().mockImplementation() and it restores the function before mocking the implementation if it's already mocked.

This PR creates a new mock function that does everything spyOnImplementing does and more, and uses it everywhere we were mocking stuff in the past.

Copy link

changeset-bot bot commented Dec 27, 2023

⚠️ No Changeset found

Latest commit: 0edff2e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@scott-rc scott-rc force-pushed the sc/consolidate-mocks branch 4 times, most recently from b53abd3 to cd7882e Compare January 4, 2024 16:10
@@ -317,8 +317,6 @@ describe("Directory.hashes", () => {
} else {
expect(mapValues(hashes, (hash) => hash.permissions)).toEqual(mapValues(hashes, () => undefined));
}

expect.assertions(2);
Copy link
Collaborator Author

@scott-rc scott-rc Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to remove this because the new mock function, which is used a few times before each test, uses expect on its arguments making this assertion fail.

@scott-rc scott-rc merged commit 63759bd into main Jan 4, 2024
7 checks passed
@scott-rc scott-rc deleted the sc/consolidate-mocks branch January 4, 2024 16:43
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.

1 participant