-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Explicit Resource Management support in mocked functions #7927
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
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think this is nice to have. Vitest should already support using at least on typescript out of the box since esbuild transpiles it #4409, so you can probably add a test with using like
vitest/test/core/test/esnext.test.ts
Lines 15 to 24 in 30b709c
| it('new "using" feature', () => { | |
| let getResource = (): any => { | |
| throw new Error('don\'t call me') | |
| } | |
| { | |
| using resource = resourceful('foo') | |
| getResource = () => resource.resource | |
| } | |
| expect(getResource()).toBe(null) | |
| }) |
|
This looks good to me, but seems like tests are failing (ignore the browser ones) |
|
never mind - I see that the core tests are failing as well |
|
(non-browser) tests are fixed - the dispose was holding onto the function reference instead of using the key we can spy on. |
Description
Support explicit resource management with mocked functions, meaning mockRestore can be called automatically once scope is exited.
This is very convenient, but also good for Jest parity - Jest added it here jestjs/jest#14895 and released in v30.0.0-alpha.3.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.