mirror of https://github.com/sveltejs/svelte
parent
4599d4161e
commit
637b2545ca
@ -0,0 +1,16 @@
|
||||
import { sleep } from './sleep.js';
|
||||
|
||||
export default {
|
||||
html: `
|
||||
<p>loading...</p>
|
||||
`,
|
||||
|
||||
test({ assert, component, target }) {
|
||||
return sleep(50).then(() => {
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<p>the answer is 42</p>
|
||||
<p>count: 1</p>
|
||||
`);
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
import { sleep } from './sleep.js';
|
||||
|
||||
let count = 0;
|
||||
|
||||
const get_promise = () => {
|
||||
return sleep(10).then(() => {
|
||||
count += 1;
|
||||
return 42;
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
{#await get_promise()}
|
||||
<p>loading...</p>
|
||||
{:then value}
|
||||
<p>the answer is {value}</p>
|
||||
<p>count: {count}</p>
|
||||
{/await}
|
@ -0,0 +1,11 @@
|
||||
export let stopped = false;
|
||||
|
||||
export const stop = () => stopped = true;
|
||||
|
||||
export const sleep = ms => new Promise(f => {
|
||||
if (stopped) return;
|
||||
setTimeout(() => {
|
||||
if (stopped) return;
|
||||
f();
|
||||
}, ms);
|
||||
});
|
Loading…
Reference in new issue