mirror of https://github.com/sveltejs/svelte
parent
e538bc8bae
commit
91a1561a8a
@ -0,0 +1,63 @@
|
|||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
thePromise: new Promise(_ => {})
|
||||||
|
},
|
||||||
|
|
||||||
|
html: `
|
||||||
|
loading...
|
||||||
|
`,
|
||||||
|
|
||||||
|
async test({ assert, component, target }) {
|
||||||
|
await (component.thePromise = Promise.resolve([10, 11, 12, 13, 14, 15]));
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<p>[1] 11</p>
|
||||||
|
<p>[3] 13</p>
|
||||||
|
<p>[4] 14</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
await (component.thePromise = Promise.resolve({ 1: 21, 3: 23, 4: 24 }));
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<p>[1] 21</p>
|
||||||
|
<p>[3] 23</p>
|
||||||
|
<p>[4] 24</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await (component.thePromise = Promise.reject([30, 31, 32, 33, 34, 35]));
|
||||||
|
} catch (e) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<p>[0] 30</p>
|
||||||
|
<p>[2] 32</p>
|
||||||
|
<p>[5] 35</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await (component.thePromise = Promise.reject({ 0: 40, 2: 42, 5: 45 }));
|
||||||
|
} catch (e) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<p>[0] 40</p>
|
||||||
|
<p>[2] 42</p>
|
||||||
|
<p>[5] 45</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
<script>
|
||||||
|
export let thePromise;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#await thePromise}
|
||||||
|
loading...
|
||||||
|
{:then { 1: a, 3: b, 4: c }}
|
||||||
|
<p>[1] {a}</p>
|
||||||
|
<p>[3] {b}</p>
|
||||||
|
<p>[4] {c}</p>
|
||||||
|
{:catch { 0: d, 2: e, 5: f }}
|
||||||
|
<p>[0] {d}</p>
|
||||||
|
<p>[2] {e}</p>
|
||||||
|
<p>[5] {f}</p>
|
||||||
|
{/await}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
export default {
|
||||||
|
async test({ assert, target }) {
|
||||||
|
await Promise.resolve();
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<p>prop-1: 1</p>
|
||||||
|
<p>prop4: 4</p>
|
||||||
|
<p>rest: {"prop2":2,"prop-3":3}</p>
|
||||||
|
<p>prop-7: 7</p>
|
||||||
|
<p>prop6: 6</p>
|
||||||
|
<p>rest: {"prop-5":5,"prop8":8}</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
<script>
|
||||||
|
const object = Promise.resolve({ 'prop-1': 1, 'prop2': 2, 'prop-3': 3, 'prop4': 4 });
|
||||||
|
const objectReject = Promise.reject({ 'prop-5': 5, 'prop6': 6, 'prop-7': 7, 'prop8': 8 });
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#await object then { 'prop-1': prop1, 'prop4': fourthProp, ...rest }}
|
||||||
|
<p>prop-1: {prop1}</p>
|
||||||
|
<p>prop4: {fourthProp}</p>
|
||||||
|
<p>rest: {JSON.stringify(rest)}</p>
|
||||||
|
{/await}
|
||||||
|
|
||||||
|
{#await objectReject then value}
|
||||||
|
resolved
|
||||||
|
{:catch { 'prop-7': prop7, 'prop6': sixthProp, ...rest }}
|
||||||
|
<p>prop-7: {prop7}</p>
|
||||||
|
<p>prop6: {sixthProp}</p>
|
||||||
|
<p>rest: {JSON.stringify(rest)}</p>
|
||||||
|
{/await}
|
||||||
|
|
||||||
Loading…
Reference in new issue