-
Notifications
You must be signed in to change notification settings - Fork 668
Testing this.$root.$emit with wrapper.emitted #980
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
Comments
I've marked this as a feature request since (as you suspected) this is not currently intended behavior, but I can see that it could be useful. |
You can do this by creating a wrapper from the $root: it('captures emitted events on $root instance', () => {
const wrapper = mount(TestComponent)
wrapper.vm.$root.$emit('foo')
const rootWrapper = createWrapper(wrapper.vm.$root)
expect(rootWrapper.emitted('foo')).to.exist
}) |
I did what you did but
It should normally populate the Modal with slot but it doesn't |
Catching the event doest mean it does function in it ? I have a parent
the Mocal listen to $root.$on("openModal") |
ok my bad it is working... |
Version
1.0.0-beta.25
Reproduction link
https://jsfiddle.net/rossta/50wL7mdz/749387/
Steps to reproduce
Given a component that triggers an event on its root via
this.$root.$emit
:Test the event is emitted using the wrapper API, i.e.,
wrapper.emitted('say')
:What is expected?
In version
1.0.0-beta.16
, thewrapper.emitted('say')
test passes for the event emitted on the component's root.What is actually happening?
In version
1.0.0-beta.25
, the test does not pass.I'm actually not sure what the intended behavior since I do not believe it is documented; I wanted to raise the issue just in case this change was not intended.
We came across this change in behavior while upgrading from
1.0.0-beta.16
to1.0.0-beta.25
.For those interested, an alternative way to test this behavior is suggested in #481 by overriding the
parentComponent
option, which will behave as the$root
component.The text was updated successfully, but these errors were encountered: