'Mockzilla webextension how to mock Runtime.Port.onMessage event

So i want to be able to emit an event for a port (to mock the port). It seems I should be able to use "mockzilla webextension" to mock this event emiting. My code simplified is below:

import "mockzilla-webextension";

const [runtimePort, mockRuntimePort, mockzillaRuntimeNode] = deepMock<Runtime.Port>("Runtime.Port", false)

mockBrowser.runtime.connectNative.expect("native-name").andReturn(runtimePort) // this will allow script under test to get mocked port (that will listen to "onMessage")

I thought I could then go:

const onMessageEventMock = mockEvent(mockRuntimePort.onMessage)
onMessageEventMock.emit(...)

but this gets error: "Error: Expect a mock value, but found a mock node at Runtime.Port.onMessage".

Can I do this? How am I able to?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source