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: spy.mockRevert #6378

Closed
wants to merge 16 commits into from

Conversation

Lordfirespeed
Copy link

Description

Adds a new method mockRevert to spies. It's in the same vein as mockClear, mockReset, mockRestore - it is most similar to mockRestore, with the key difference being that it does not 'un-spy' mocks created with vi.spyOn().

See #6308 for discussion.

PR Checklist

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci. (I am waiting for playwright to install)

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Aug 21, 2024

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 95a1d1c
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/66c7bf6c885d9c000843e32d
😎 Deploy Preview https://deploy-preview-6378--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Lordfirespeed
Copy link
Author

Lordfirespeed commented Aug 22, 2024

Hey, I'd appreciate some input on the CI failing - node-20, macos-14 was passing before my rebase onto main 🤔

@sheremet-va
Copy link
Member

Hey, I'd appreciate some input on the CI failing - node-20, macos-14 was passing before my rebase onto main 🤔

It's just flaky, don't worry

@sheremet-va sheremet-va added the p2-to-be-discussed Enhancement under consideration (priority) label Aug 22, 2024
docs/api/vi.md Outdated Show resolved Hide resolved
docs/config/index.md Outdated Show resolved Hide resolved
@sheremet-va sheremet-va removed the p2-to-be-discussed Enhancement under consideration (priority) label Aug 29, 2024
@sheremet-va
Copy link
Member

The team thinks it's better to restore the implementation in mockRevert instead of resetting it to a () => {} without adding a new method.

@Lordfirespeed
Copy link
Author

Lordfirespeed commented Aug 29, 2024

mockRevert is the function this PR adds - do you mean mockReset ?

Wouldn't that be a breaking change with respect to the Jest compatibility layer?

I am imagining like:

import { expect, it, vi } from "vitest"

// this test passes with jest
// it would not pass in vitest with the proposed changes to `mockReset`
it("should reset", () => {
  const value = 0
  const fn = vi.fn(() => {
    value++
  })
  fn()
  expect(value).toBe(1)
  fn.mockReset()
  fn()
  expect(value).toBe(1)
})

Please let me know if I have misunderstood anything ❤️

Sorry, I am happy to help, I just want to make sure the discussion was rigorous before proceeding 😅

@sheremet-va
Copy link
Member

mockRevert is the function this PR adds - do you mean mockReset ?

Wouldn't that be a breaking change with respect to the Jest compatibility layer?

Yes and yes

@Lordfirespeed
Copy link
Author

Alright - I think I will close this for now, then, and open a new PR for that

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

Successfully merging this pull request may close these issues.

2 participants