mirror of https://github.com/sveltejs/svelte
Merge pull request #2004 from sveltejs/gh-1995
Update await-block to use on_outro and check_outros - #1995pull/2007/head
commit
add3b303dc
@ -0,0 +1,5 @@
|
|||||||
|
{value}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export let value = 'Loading...';
|
||||||
|
</script>
|
@ -0,0 +1,29 @@
|
|||||||
|
export default {
|
||||||
|
async test({ assert, component, target }) {
|
||||||
|
let resolve, reject;
|
||||||
|
let promise = new Promise(ok => resolve = ok);
|
||||||
|
|
||||||
|
component.promise = promise;
|
||||||
|
assert.htmlEqual(target.innerHTML, 'Loading...');
|
||||||
|
|
||||||
|
resolve(42);
|
||||||
|
await promise;
|
||||||
|
assert.htmlEqual(target.innerHTML, '42');
|
||||||
|
|
||||||
|
promise = new Promise((ok, fail) => reject = fail);
|
||||||
|
component.promise = promise;
|
||||||
|
assert.htmlEqual(target.innerHTML, 'Loading...');
|
||||||
|
|
||||||
|
reject(99);
|
||||||
|
await promise.then(null, () => {});
|
||||||
|
assert.htmlEqual(target.innerHTML, '99');
|
||||||
|
|
||||||
|
promise = new Promise(ok => resolve = ok);
|
||||||
|
component.promise = promise;
|
||||||
|
assert.htmlEqual(target.innerHTML, 'Loading...');
|
||||||
|
|
||||||
|
resolve(1);
|
||||||
|
await promise;
|
||||||
|
assert.htmlEqual(target.innerHTML, '1');
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,12 @@
|
|||||||
|
{#await promise}
|
||||||
|
<Widget />
|
||||||
|
{:then result}
|
||||||
|
<Widget value="{result}" />
|
||||||
|
{:catch err}
|
||||||
|
<Widget value="{err}" />
|
||||||
|
{/await}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Widget from './Widget.html';
|
||||||
|
export let promise = Promise.resolve();
|
||||||
|
</script>
|
Loading…
Reference in new issue