diff --git a/browser-polyfill.in.js b/browser-polyfill.in.js index df26346..b7041e7 100644 --- a/browser-polyfill.in.js +++ b/browser-polyfill.in.js @@ -105,13 +105,15 @@ if (typeof browser === "undefined") { * The generated wrapper function. */ const wrapAsyncFunction = (name, metadata) => { + const pluralizeArguments = (numArgs) => numArgs == 1 ? "argument" : "arguments"; + return function asyncFunctionWrapper(target, ...args) { if (args.length < metadata.minArgs) { - throw new Error(`Expected at least ${metadata.minArgs} arguments for ${name}(), got ${args.length}`); + throw new Error(`Expected at least ${metadata.minArgs} ${pluralizeArguments(metadata.minArgs)} for ${name}(), got ${args.length}`); } if (args.length > metadata.maxArgs) { - throw new Error(`Expected at most ${metadata.maxArgs} arguments for ${name}(), got ${args.length}`); + throw new Error(`Expected at most ${metadata.maxArgs} ${pluralizeArguments(metadata.maxArgs)} for ${name}(), got ${args.length}`); } return new Promise((resolve, reject) => { diff --git a/test/test-async-functions.js b/test/test-async-functions.js index 5c8e8de..836163a 100644 --- a/test/test-async-functions.js +++ b/test/test-async-functions.js @@ -79,7 +79,7 @@ describe("browser-polyfill", () => { return setupTestDOMWindow(fakeChrome).then(window => { throws(() => { window.browser.runtime.sendMessage(); - }, "Expected at least 1 arguments for sendMessage(), got 0"); + }, "Expected at least 1 argument for sendMessage(), got 0"); throws(() => { window.browser.runtime.sendMessage("0", "1", "2", "3");