Skip to content

Commit

Permalink
fix: resolve to undefined instead of an empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob--W authored and rpl committed Jul 4, 2018
1 parent 4e1e98a commit d612352
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/browser-polyfill.js
Expand Up @@ -97,7 +97,7 @@ if (typeof browser === "undefined") {
return (...callbackArgs) => {
if (chrome.runtime.lastError) {
promise.reject(chrome.runtime.lastError);
} else if (metadata.singleCallbackArg || callbackArgs.length === 1) {
} else if (metadata.singleCallbackArg || callbackArgs.length <= 1) {
promise.resolve(callbackArgs[0]);
} else {
promise.resolve(callbackArgs);
Expand Down
8 changes: 8 additions & 0 deletions test/test-async-functions.js
Expand Up @@ -12,6 +12,7 @@ describe("browser-polyfill", () => {
alarms: {clear: sinon.stub()},
runtime: {
lastError: null,
openOptionsPage: sinon.stub(),
requestUpdateCheck: sinon.stub(),
},
tabs: {
Expand All @@ -31,17 +32,24 @@ describe("browser-polyfill", () => {
fakeChrome.runtime.requestUpdateCheck
.onFirstCall().callsArgWith(0, "res1", "res2");

// Test for no callback arguments.
fakeChrome.runtime.openOptionsPage
.onFirstCall().callsArg(0);

return Promise.all([
window.browser.alarms.clear("test1"),
window.browser.tabs.query({active: true}),
window.browser.runtime.requestUpdateCheck(),
window.browser.runtime.openOptionsPage(),
]);
}).then(results => {
equal(results[0], "res1", "Fake alarms.clear call resolved to a single value");
deepEqual(results[1], ["res1", "res2"],
"Fake tabs.query resolved to an array of values");
deepEqual(results[2], ["res1", "res2"],
"Fake runtime.requestUpdateCheck resolved to an array of values");

equal(results[3], undefined, "Fake runtime.openOptionsPage resolved to a void value.");
});
});

Expand Down

0 comments on commit d612352

Please sign in to comment.