From 9a04fc387679f34ef45ae29575ec8779684bb8d5 Mon Sep 17 00:00:00 2001 From: Luca Greco Date: Wed, 2 Nov 2016 21:45:02 +0100 Subject: [PATCH] fix: pluralize argument in raised error message --- browser-polyfill.in.js | 6 ++++-- test/test-async-functions.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) 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");