-
Notifications
You must be signed in to change notification settings - Fork 257
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
fix(emit): force event handling even with fake timers #1856
Conversation
✅ Deploy Preview for vue-test-utils-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
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.
I actually think this is a clever solution that should prevent others from ever having to worry about the fake timers issue, and everything will "just work" as expected. This was very similar to my first fix in my project's codebase when I discovered the issue, but I had to add it to every event using the second arg to trigger
.
Although it's tied to behavior in vue internals that could change, I think that's fine since this is the official testing library for vue. The comment does a good job of explaining what the workaround is for, and if vue changes implementation it should be easy to find the code that needs to be understood to fix it if it breaks.
Nice work!
tests/trigger.spec.ts
Outdated
wrapper.setProps({ label: 'foo' }) | ||
|
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.
This line with wrapper.setProps
isn't needed, I forgot to remove it from an earlier version when I was tinkering with the repro.
c442f76
to
2fe61b7
Compare
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.
Looks ok to me
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.
Wow, what a hack. I don't know of a better way to do this but this feels pretty dirty. 🤷 If it works, it works, nice fix.
Fixes #1854
I'm not 100% convinced this is the proper way to fix it, but I don't have a better idea at the moment.
Setting
_vts
to Date.now() + 1 tricks Vue into thinking it has to handle the event even ifDate.now()
is faked and always returns the same value https://github.com/vuejs/core/blob/5ee40532a63e0b792e0c1eccf3cf68546a4e23e9/packages/runtime-dom/src/modules/events.ts#L100-L104I hope this doesn't introduce other subtle issues. It would be great to only do this if the test is running with a fake Date, but I don't know how we can find out reliably for jest or vitest or even a manually mocked Date object.