Skip to content

Conversation

@sirlancelot
Copy link
Contributor

@mcous
Copy link
Owner

mcous commented Oct 24, 2025

Thanks for the contribution @sirlancelot! Looks like there's a typescript check failing, mind taking a look?

Also, could you please add a test to validate the behavior? Feel free to bump Vitest to v4 in dev dependencies to do so (on the off chance this causes other things to blow up feel free to ping me)

@mcous
Copy link
Owner

mcous commented Oct 25, 2025

Little update: I messed around with this a little and getting the typing correct is non-trivial! If you haven't already, can you make sure "allow maintainers to push changes" is checked for this PR? (Already set!) I should be able to get this sorted on Sunday

@sirlancelot
Copy link
Contributor Author

I adjusted the signature and added a test. Hopefully it passes the checks. Thanks for this library!

@sirlancelot
Copy link
Contributor Author

I didn't want to update Vitest within this project because it would require updating all the unit tests' vi.fn() that use arrow functions. I also wanted to make sure the change is backwards compatible.

@mcous mcous changed the title Use function signature to support Vitest v4 fix: support mocked constructors in Vitest v4 Oct 27, 2025
@mcous mcous merged commit 5ee07dd into mcous:main Oct 27, 2025
12 of 22 checks passed
@mcous
Copy link
Owner

mcous commented Oct 27, 2025

Thanks for the fix! This has been released in v0.9.0

I didn't want to update Vitest within this project because it would require updating all the unit tests' vi.fn() that use arrow functions

Thankfully, this was not necessary. It is only necessary to use a function expression in the specific case of using this inside a thenDo. Otherwise arrow functions continue to work as they did previously

I also wanted to make sure the change is backwards compatible.

It took some TypeScript gymnastics (see #34), but even with this change vitest-when continues to support vitest all the way back to 0.x

@sirlancelot sirlancelot deleted the patch-1 branch November 5, 2025 23:55
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.

2 participants