acvetkov / sinon-chrome

Testing chrome extensions with Node.js
ISC License
437 stars 48 forks source link

Question: How to send response messages, if my code sends messages #62

Closed kangaro0 closed 7 years ago

kangaro0 commented 7 years ago

Hey,

I'm trying to test my extension's popup code. The popup has a init function which catches data from the background page. In order to do that the popup sends a request to the background page via chrome.runtime.sendMessage( ... ).

Now I tried different approaches how to 'fake' the response from the background page, currently I'm trying this approach.

But the the listener doesn't get called, once the Popup sends the request... What am I doing wrong?

acvetkov commented 7 years ago

@kangaro0 Hi.

Chrome api is just stubs without any behavior. You should manually trigger event in your case.

chrome.runtime.onMessage.addListener(functionSpy);

chrome.runtime.onMessage.trigger(params);

assert.calledOnce(functionSpy.withArgs(params));
kangaro0 commented 7 years ago

Alright. I was on the wrong path here.... Thanks!