I'm trying to write a unit test for a VueJS 2 component that has a dynamic component that changes as the state changes.
<template>
<div>
<component ref="dynamicComponent" id="dynamicComponent" :is="someDynamicType" @custom-event="handleCustomEvent">
</component>
</div>
</template>
What i'm trying to test is that the parent component is handling the custom-event from the child dynamic component correctly. However, the problem I'm running into is that I cannot seem to get a reference to the child dynamic component.
I've tried
await wrapper.findComponent('#dynamicComponent').vm.$emit("custom-event", {});
and
await wrapper.find({ref: 'dynamicComponent'}).vm.$emit("custom-event", {});
and I also tried using the known type of the dynamic component
await wrapper.findComponent(KnownSubType).vm.$emit("custom-event", {});
but in each case, I get the following error
TypeError: Cannot read properties of undefined (reading '$emit')
Is there another way to obtain the component so that I can emit the custom event or is there another way to trigger the event to test my parent component?