#How to test emit listener?

7 messages · Page 1 of 1 (latest)

hushed parcel
#

Hi,
I have this simple code in my frontend:
listen('my-event', cb)
How do I evoke the listener in my unit tests?

vast ivy
hushed parcel
#

It doesn't say how to do it IMO. Am I missing something?

#

I mocked the IPC according to it and it's fine testing a call to the rust part. Now I want to test the listen - so I need to mock the emit part which is coming from Rust

#

Oh - I tried this:

const eventCallbackId = `_${args.message.onEventFn}`;
                    const eventEmitter = window[eventCallbackId];

But it doesn't work. args.message is undefined.

vast ivy
#

So I think I misread your initial question. I don’t think we have a mocking service for event listeners, but I may be mistaken. Would you be so kind as to file a feature request? Thankyou!

hushed parcel
#

What I'm doing now is mock listen itself, get the Callback and fire it when the IPC mock resolves. It is cumbersome and thought there might be a "cleaner" way to do it.
Adding a feature request. Thanks!