Description
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
:
// ChildComponent
export default {
mounted() {
this.$root.$emit('say', 'New message!')
},
render: h => h('div', 'Child content')
};
Test the event is emitted using the wrapper API, i.e., wrapper.emitted('say')
:
import { mount } from '@vue/test-utils'
import ChildComponent from './ChildComponent.vue'
describe('ChildComponent', () => {
it('emits event to $root', () => {
const wrapper = mount(ChildComponent)
expect(wrapper.emitted('say')).toBeTruthy() // test fails in 1.0.0-beta.25
})
})
What is expected?
In version 1.0.0-beta.16
, the wrapper.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
to 1.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.