fix: pluralize argument in raised error message
This commit is contained in:
parent
705e93bc2f
commit
9a04fc3876
|
@ -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) => {
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue