Skip to content

Commit

Permalink
added regression test for issue babel#4943
Browse files Browse the repository at this point in the history
  • Loading branch information
hulkish committed May 2, 2017
1 parent 750eec4 commit 13b125d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
@@ -0,0 +1,51 @@
function mandatory(paramName) {
throw new Error(`Missing parameter: ${paramName}`);
}

function shouldNotHappen() {
throw new Error("should not happen");
}

async function foo({ a, b = mandatory("b") } = {}) {
return Promise.resolve(b);
}

async function bar(a = mandatory("a"), b = mandatory("b")) {
return Promise.resolve(b);
}

assert.doesNotThrow(() => {
foo().then(() => true).catch(() => true);
});

assert.doesNotThrow(() => {
bar().then(() => true).catch(() => true);
});

async function fooUsage() {
try {
await foo().then(shouldNotHappen);
} catch (err) {
assert.equal(err.message, "Missing parameter: b");
}
};

async function barUsage() {
try {
await bar().then(shouldNotHappen);
} catch (err) {
assert.equal(err.message, "Missing parameter: a");
}
}

fooUsage().catch((err) => {
if (err instanceof AssertionError) {
throw err;
}
});

barUsage().catch((err) => {
if (err instanceof AssertionError) {
throw err;
}
});

0 comments on commit 13b125d

Please sign in to comment.