forked from sveltejs/svelte
-
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.
await: rethrow error when there is no catch block, fixes sveltejs#5129
- Loading branch information
1 parent
fc7e99e
commit e297182
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
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
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,44 @@ | ||
let fulfil; | ||
|
||
let promise = new Promise(f => { | ||
fulfil = f; | ||
}); | ||
|
||
export default { | ||
props: { | ||
promise | ||
}, | ||
|
||
html: ` | ||
<p>loading...</p> | ||
`, | ||
|
||
test({ assert, component, target }) { | ||
fulfil(42); | ||
|
||
return promise | ||
.then(() => { | ||
assert.htmlEqual(target.innerHTML, ` | ||
<p>loaded</p> | ||
`); | ||
|
||
let reject; | ||
|
||
promise = new Promise((f, r) => { | ||
reject = r; | ||
}); | ||
|
||
component.promise = promise; | ||
|
||
assert.htmlEqual(target.innerHTML, ` | ||
<p>loading...</p> | ||
`); | ||
|
||
reject(new Error('this error should be thrown')); | ||
return promise; | ||
}) | ||
.catch((err) => { | ||
assert.equal(err.message, 'this error should be thrown'); | ||
}); | ||
} | ||
}; |
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,9 @@ | ||
<script> | ||
export let promise; | ||
</script> | ||
|
||
{#await promise} | ||
<p>loading...</p> | ||
{:then value} | ||
<p>loaded</p> | ||
{/await} |