acvetkov / sinon-chrome

Testing chrome extensions with Node.js
ISC License
434 stars 46 forks source link

chrome.storage.onChanged.addListener #95

Open maximedb opened 4 years ago

maximedb commented 4 years ago

How would you mock chrome.storage.onChanged.addListener with sinon-chrome ?

Thanks!

fregante commented 8 months ago

Working example:

const spy = jest.fn();
chrome.storage.onChanged.addListener(spy);
chrome.storage.onChanged.trigger({unrelatedKey: 123}, 'local')
expect(spy).toHaveBeenCalledWith({unrelatedKey: 123}, 'local');