Skip to content
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/emitted events cache #1449

Merged
merged 1 commit into from Apr 26, 2022
Merged

Conversation

BrettLargent
Copy link
Contributor

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.

@netlify
Copy link

netlify bot commented Apr 25, 2022

Deploy Preview for vue-test-utils-docs ready!

Name Link
🔨 Latest commit 193a0f4
🔍 Latest deploy log https://app.netlify.com/sites/vue-test-utils-docs/deploys/6267f3efa48af4000971fea4
😎 Deploy Preview https://deploy-preview-1449--vue-test-utils-docs.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 site settings.

Copy link
Member

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

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

Just one question about a possible additional assertion. Also, you might need to run prettier to ensure all the files are formatted correctly - I think the command you want is yarn lint:fix (see package.json).


const wrapper1 = mount(Foo)
await wrapper1.trigger('click')
expect(wrapper1.emitted('foo')).toHaveLength(1)
Copy link
Member

Choose a reason for hiding this comment

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

Should we also assert

expect(wrapper2.emitted('foo')).toHaveLength(0)

Here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We would have to wait until after wrapper2 is mounted. We can do that, but the ultimate point of the test is to ensure that subsequent mounts no longer clear the emit history for previously mounted components.

src/emit.ts Outdated
@@ -11,7 +11,7 @@ const enum DevtoolsHooks {
COMPONENT_EMIT = 'component:emit'
}

let events: Events
let events: Events = {};
Copy link
Member

Choose a reason for hiding this comment

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

Not directly relevant but as a refactor in the future, I wonder if we should use WeakMap instead of a record here 🤔

Copy link
Member

@cexbrayat cexbrayat left a comment

Choose a reason for hiding this comment

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

LGTM

The PR needs to be fixed for the linting issues.
I would also squash the commits, and mention that they fix issue #1445 in the commit message.

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
@BrettLargent
Copy link
Contributor Author

BrettLargent commented Apr 26, 2022

LGTM

The PR needs to be fixed for the linting issues. I would also squash the commits, and mention that they fix issue #1445 in the commit message.

linting issues fixed, commits have been squashed, and has a footer mention that it fixes #1445 👍

@cexbrayat cexbrayat merged commit c24aec0 into vuejs:main Apr 26, 2022
@cexbrayat
Copy link
Member

Thanks @BrettLargent !

@BrettLargent
Copy link
Contributor Author

Thanks @BrettLargent !

No problem! Thank you all for your responsiveness and feedback. Glad we got this squashed quickly 💯

@lmiller1990
Copy link
Member

I will release this soon! Please wait a few days.

@BrettLargent
Copy link
Contributor Author

Hey all!

It's been a while since this was merged, but I'm still having the same problems with v0.17.1. Can anyone confirm whether this was ever released for me?

Thanks!

@cexbrayat
Copy link
Member

Yes it has been released. Are you using VTU v2.0.2?

@BrettLargent
Copy link
Contributor Author

🤦‍♂️ nope, I was updating the wrong dependency. Sorry for that!

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.

None yet

3 participants