mirror of https://github.com/sveltejs/svelte
fix not passing child_ctx for catch block (#5261)
parent
76b7196a1b
commit
e879cb5a4c
@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
export let count;
|
||||||
|
export let value;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>count: {count}</div>
|
||||||
|
<div>value: {value}</div>
|
@ -0,0 +1,64 @@
|
|||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
thePromise: new Promise((_) => {}),
|
||||||
|
count: 0,
|
||||||
|
},
|
||||||
|
|
||||||
|
html: `
|
||||||
|
<div><p>loading...</p></div>
|
||||||
|
`,
|
||||||
|
|
||||||
|
async test({ assert, component, target }) {
|
||||||
|
await (component.thePromise = Promise.resolve({ value: "success", Component: component.Component }));
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<div>Resolved:
|
||||||
|
<div>count: 0</div>
|
||||||
|
<div>value: success</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
component.count = 5;
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<div>Resolved:
|
||||||
|
<div>count: 5</div>
|
||||||
|
<div>value: success</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await (component.thePromise = Promise.reject({ value: "failure", Component: component.Component }));
|
||||||
|
} catch (error) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<div>Rejected:
|
||||||
|
<div>count: 5</div>
|
||||||
|
<div>value: failure</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
component.count = 10;
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<div>Rejected:
|
||||||
|
<div>count: 10</div>
|
||||||
|
<div>value: failure</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
@ -0,0 +1,16 @@
|
|||||||
|
<script>
|
||||||
|
import Component from './Component.svelte';
|
||||||
|
export let thePromise;
|
||||||
|
export let count;
|
||||||
|
export { Component }
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{#await thePromise}
|
||||||
|
<p>loading...</p>
|
||||||
|
{:then { value: theValue, Component }}
|
||||||
|
Resolved: <svelte:component this={Component} {count} value={theValue} />
|
||||||
|
{:catch { value: theError, Component } }
|
||||||
|
Rejected: <svelte:component this={Component} {count} value={theError} />
|
||||||
|
{/await}
|
||||||
|
</div>
|
@ -0,0 +1,5 @@
|
|||||||
|
<script>
|
||||||
|
export let count;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>count: {count}</div>
|
@ -0,0 +1,60 @@
|
|||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
thePromise: new Promise((_) => {}),
|
||||||
|
count: 0,
|
||||||
|
},
|
||||||
|
|
||||||
|
html: `
|
||||||
|
<div><p>loading...</p></div>
|
||||||
|
`,
|
||||||
|
|
||||||
|
async test({ assert, component, target }) {
|
||||||
|
await (component.thePromise = Promise.resolve(component.Component));
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<div>Resolved:
|
||||||
|
<div>count: 0</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
component.count = 5;
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<div>Resolved:
|
||||||
|
<div>count: 5</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await (component.thePromise = Promise.reject(component.Component));
|
||||||
|
} catch (error) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<div>Rejected:
|
||||||
|
<div>count: 5</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
component.count = 10;
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<div>Rejected:
|
||||||
|
<div>count: 10</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
@ -0,0 +1,16 @@
|
|||||||
|
<script>
|
||||||
|
import Component from './Component.svelte';
|
||||||
|
export let thePromise;
|
||||||
|
export let count;
|
||||||
|
export { Component }
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{#await thePromise}
|
||||||
|
<p>loading...</p>
|
||||||
|
{:then theValue}
|
||||||
|
Resolved: <svelte:component this={theValue} {count} />
|
||||||
|
{:catch theError}
|
||||||
|
Rejected: <svelte:component this={theError} {count} />
|
||||||
|
{/await}
|
||||||
|
</div>
|
Loading…
Reference in new issue