Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing onMessage listeners #136

Open
kmarple1 opened this issue Apr 22, 2021 · 3 comments
Open

Testing onMessage listeners #136

kmarple1 opened this issue Apr 22, 2021 · 3 comments

Comments

@kmarple1
Copy link

kmarple1 commented Apr 22, 2021

I'm attempting to test my onMessage listeners, but I keep getting the error TypeError: sendResponse is not a function. It appears that the implementation of runtime.sendMessage accepts a callback as the second argument, but doesn't actually pass it to the listener.

I've also tried the MDN-recommended method of returning a promise from the onMessage listener and using .then() from runtime.sendMessage, but this doesn't work either.

My workaround thus far has been to export the listener function and hit it directly. This works but is less than ideal.

@clarkbw
Copy link
Owner

clarkbw commented Apr 23, 2021

Looks like we check that we call the callback

expect(callback).toHaveBeenCalledTimes(1);

And yes, looks like you're right that we don't pass it along

sendMessage: jest.fn((message, cb) => {

Can you check that this is the correct behaviour and open a PR fixing the library? thx!

@kmarple1
Copy link
Author

After some reading on MDN, it seems like the callback itself is deprecated, so there's probably no point in adding it now. The expected behavior would be for everything to be Promise-based, but that would likely be a major revision.

@clarkbw
Copy link
Owner

clarkbw commented Apr 23, 2021

We handle promises but we probably don't do it correctly

return Promise.resolve();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants