Closed epszaw closed 3 years ago
Hi! You should definitely use fireEvent
instead of stepping into Vue internals to emit a custom event – this makes your test rely on implementation details, and this is what we're trying to avoid here with Vue Testing Library. The MutationObserver error looks related to jest/jsdom version: https://github.com/testing-library/dom-testing-library/issues/477
I see, will try it. Thank you!
@afontcu, can I trigger a component's custom event using fireEvent
? I have a use case in which creating the context to emit the custom event using clicks and filling forms is quite complex, so I would rather just emit this event directly, but I haven't been able to accomplish this. I tried creating a custom event with createEvent
and then passing it to fireEvent
pointing to the custom component via a data-testid
, but this didn't work. Am I missing something? Is this even possible?
Thanks beforehand for your time and for this awesome library :)
For example, we have two components:
Component
A
emitscustom-event
which should be handled in theB
component.How I should fire it correctly?
I found very similar workaround to official
@vue/text-utils
recommendation – to use$emit
. It looks like:May be we should describe this moment in documentation, because
fireEvent
can confuse developers?Also, if we try to use
fireEvent
with child component and not custom event we can face an error:TypeError: MutationObserver is not a constructor