mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
806 B
56 lines
806 B
3 years ago
|
let fulfil;
|
||
|
|
||
|
let thePromise = new Promise(f => {
|
||
|
fulfil = f;
|
||
|
});
|
||
|
|
||
|
export default {
|
||
|
props: {
|
||
|
thePromise
|
||
|
},
|
||
|
|
||
|
html: `
|
||
|
<br>
|
||
|
<br>
|
||
|
<p>the promise is pending</p>
|
||
|
`,
|
||
|
|
||
|
async test({ assert, component, target }) {
|
||
|
fulfil();
|
||
|
|
||
|
await thePromise;
|
||
|
|
||
|
assert.htmlEqual(target.innerHTML, `
|
||
|
<p>the promise is resolved</p>
|
||
|
<br>
|
||
|
<p>the promise is resolved</p>
|
||
|
<br>
|
||
|
<p>the promise is resolved</p>
|
||
|
`);
|
||
|
|
||
|
let reject;
|
||
|
|
||
|
thePromise = new Promise((f, r) => {
|
||
|
reject = r;
|
||
|
});
|
||
|
|
||
|
component.thePromise = thePromise;
|
||
|
|
||
|
assert.htmlEqual(target.innerHTML, `
|
||
|
<br>
|
||
|
<br>
|
||
|
<p>the promise is pending</p>
|
||
|
`);
|
||
|
|
||
|
reject(new Error('something broke'));
|
||
|
|
||
|
await thePromise.catch(() => {});
|
||
|
|
||
|
assert.htmlEqual(target.innerHTML, `
|
||
|
<p>oh no! something broke</p>
|
||
|
<br>
|
||
|
<br>
|
||
|
`);
|
||
|
}
|
||
|
};
|