stoically/webextensions-api-fake

`browser.alarms.getAll()` returns `undefined` instead of array

Opened this issue · 3 comments

browser.alarms.getAll() should return an Array. However, it is returning undefined using v0.7.5.

const browserFake = require("webextensions-api-fake");
global.browser = browserFake();

(async () => {
    const alarms = await browser.alarms.getAll();
    console.log(alarms);
    // Should return `[]` but returns `undefined`
})();

Probably caused by a dependency. I filed a related issue acvetkov/sinon-chrome#90

browser.alarms is currently not implemented. You can see the list of working fakes here. I'll look into implementing alarms.

sinon-chrome just provides sinon stubs for all APIs and doesn't actually fake behavior, you need to define the desired behavior yourself. E.g. for alarms.getAll you could do

browser.alarms.getAll.callsFake(async () => []);

or

browser.alarms.getAll.resolves([]);

Published 0.8.0 with the alarms fake.

If you don't want to wait for the timeout or interval you could use sinon fake-timers.