From d612352bbaa4ff276ac38ce708e90bdd7a0139df Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Tue, 19 Jun 2018 22:35:41 +0200 Subject: [PATCH] fix: resolve to undefined instead of an empty array --- src/browser-polyfill.js | 2 +- test/test-async-functions.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/browser-polyfill.js b/src/browser-polyfill.js index fd20d4d..80dd81f 100644 --- a/src/browser-polyfill.js +++ b/src/browser-polyfill.js @@ -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); diff --git a/test/test-async-functions.js b/test/test-async-functions.js index dd7873a..fc6231f 100644 --- a/test/test-async-functions.js +++ b/test/test-async-functions.js @@ -12,6 +12,7 @@ describe("browser-polyfill", () => { alarms: {clear: sinon.stub()}, runtime: { lastError: null, + openOptionsPage: sinon.stub(), requestUpdateCheck: sinon.stub(), }, tabs: { @@ -31,10 +32,15 @@ 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"); @@ -42,6 +48,8 @@ describe("browser-polyfill", () => { "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."); }); });