mirror of https://github.com/sveltejs/svelte
Await: re-throw error when there is no catch block and promise is rejected (#5149)
parent
cd95654a97
commit
e0e434234d
@ -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');
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,9 @@
|
||||
<script>
|
||||
export let promise;
|
||||
</script>
|
||||
|
||||
{#await promise}
|
||||
<p>loading...</p>
|
||||
{:then value}
|
||||
<p>loaded</p>
|
||||
{/await}
|
Loading…
Reference in new issue