Skip to content

Conversation

@kirkwaiblinger
Copy link

@kirkwaiblinger kirkwaiblinger commented Dec 23, 2025

Description

This makes doMock() return a disposable that calls the corresponding doUnmock() upon being disposed.

Resolves #8425

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • 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.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

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:.

@netlify
Copy link

netlify bot commented Dec 23, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 4a830e7
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/694a0bc08cb6700008c3c1ed
😎 Deploy Preview https://deploy-preview-9332--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 project configuration.

@kirkwaiblinger kirkwaiblinger marked this pull request as ready for review December 23, 2025 09:03
}
})

test.skipIf(Symbol.dispose)('doMock works with using', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

This test seems weird, because Symbol.dispose in _incrementMock?.[Symbol.dispose] is always undefined and test always checks for _incrementMock[undefined]

Maybe it should instead check Object.keys(_incrementMock)

Copy link
Author

Choose a reason for hiding this comment

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

I had lifted the pattern from here:

describe.skipIf(Symbol.dispose)('in environments not supporting it', () => {
it('does not have dispose property', () => {
expect(vi.fn()[Symbol.dispose]).toBeUndefined()
})
})

I wasn't sure if Symbol.dispose was patched in between evaluating the skipIf condition and the test body or something, for example, by something like

Symbol.dispose ??= Symbol('dispose')


If Symbol.dispose really is undefined, then maybe we just skip the test altogether? There are already tests that assert that doMock()'s functionality works, so it doesn't really matter what the return value is in a non-using-supporting environment 🤷 Or, like you say, we could examine the keys of the object, but it's just a little weird to try to do that when we can't name the key that we're interested in.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, if there is no reason to test something, then don't test it

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.

Provide disposable APIs for releasing mocks

2 participants