acvetkov / sinon-chrome

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

Spy callbacks #42

Closed herodrigues closed 7 years ago

herodrigues commented 7 years ago

Couldn't find anything related in the examples, but how can I overcome this situation?

chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
    // [..]
    chrome.runtime.sendMessage({
           // [...]
    });
});

I want to spy chrome.tabs.query callback.

acvetkov commented 7 years ago

@herodrigues

global.chrome = require('sinon-chrome');

before(function () {
  chrome.tabs.query.yields([]);
});

it('...', function () {
  console.log(chrome.tabs.query.callCount);
  console.log(chrome.tabs.query.args);
});
herodrigues commented 7 years ago

thanks @acvetkov! You're doing a great work with sinon-chrome :smile: