forked from babel/babel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added regression test for issue babel#4943
- Loading branch information
Showing
4 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
51 changes: 51 additions & 0 deletions
51
packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/4943/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
}); |
File renamed without changes.
File renamed without changes.