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
Bug: Consecutive Mounts Clears Emitted Events Cache #1445
Comments
Nice bug report. This is a pretty big oversight, we should probably generate a unique id each time we mount a component and cache the emitted events like that, something like: {
'foo-component-1': { /* events map */ },
'foo-component-2': { /* events map */ },
} Is this something you'd like to try your hand at fixing? |
Sure, I can give it a go 👍 |
Do you all have a contribution guide or something similar? Just want to make sure I'm following expected practices. |
We don't have a contribution guide - we probably should work on one. For now, you could add your test to to the That's pretty much it! |
All good. I've created #1449 to merge in my fixes. Let me know what, if anything, needs to change. |
Refactoring attachEmitListener function to not clear entire emitted events history on every call. A new removeEventHistory has been exposed and added to the unmount method logic so that specific emit history will be cleared on wrapper unmount. Unit testing has been added as well to show that the bug has been fixed. fixes issue vuejs#1445
Refactoring attachEmitListener function to not clear entire emitted events history on every call. A new removeEventHistory has been exposed and added to the unmount method logic so that specific emit history will be cleared on wrapper unmount. Unit testing has been added as well to show that the bug has been fixed. fixes issue vuejs#1445
Describe the bug
The current
attachEmitListener
implementation that runs in themount
function clears the entirety of the events cache after a new component is mounted. This prevents a user from mounting multiple components consecutively and checking theiremitted
arrays.To Reproduce
With a test component like this:
test.vue
and a test spec file like this:
test.spec.js
You can run a test suite like vitest or jest to see that the first check of wrapper1's emitted array passes, but a subsequent check after mounting another component throws a TypeError explaining that
wrapper1.emitted()["component-mounted"]
isundefined
.Expected behavior
I expect to be able to mount any number of components without the emit history of those previously mounted components being cleared unless I deliberately want them to be cleared.
Related information:
@vue/test-utils
version: 2.0.0-rc.18Vue
version: 3.2.25vitest
version: 0.9.0node
version: v16.13.2npm
version: 8.1.2The text was updated successfully, but these errors were encountered: