mirror of https://github.com/sveltejs/svelte
Merge pull request #1988 from sveltejs/gh-1976
add nextTick lifecycle function - fixes #1976pull/1993/head
commit
c134ca2ee4
@ -0,0 +1,30 @@
|
|||||||
|
export default {
|
||||||
|
async test({ assert, component, target, window }) {
|
||||||
|
const buttons = target.querySelectorAll('button');
|
||||||
|
const click = new window.MouseEvent('click');
|
||||||
|
|
||||||
|
await buttons[0].dispatchEvent(click);
|
||||||
|
assert.deepEqual(component.snapshots, [
|
||||||
|
'before 0',
|
||||||
|
'after 1'
|
||||||
|
]);
|
||||||
|
|
||||||
|
await buttons[0].dispatchEvent(click);
|
||||||
|
assert.deepEqual(component.snapshots, [
|
||||||
|
'before 0',
|
||||||
|
'after 1',
|
||||||
|
'before 1',
|
||||||
|
'after 2'
|
||||||
|
]);
|
||||||
|
|
||||||
|
await buttons[1].dispatchEvent(click);
|
||||||
|
assert.deepEqual(component.snapshots, [
|
||||||
|
'before 0',
|
||||||
|
'after 1',
|
||||||
|
'before 1',
|
||||||
|
'after 2',
|
||||||
|
'before 2',
|
||||||
|
'after 2'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,24 @@
|
|||||||
|
<script>
|
||||||
|
import { nextTick } from 'svelte';
|
||||||
|
|
||||||
|
export let snapshots = [];
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
|
let buttons = [];
|
||||||
|
|
||||||
|
function increment() {
|
||||||
|
count += 1;
|
||||||
|
log();
|
||||||
|
}
|
||||||
|
|
||||||
|
function log() {
|
||||||
|
snapshots.push(`before ${buttons[0].textContent}`);
|
||||||
|
|
||||||
|
nextTick(() => {
|
||||||
|
snapshots.push(`after ${buttons[0].textContent}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button bind:this={buttons[0]} on:click={increment}>{count}</button>
|
||||||
|
<button bind:this={buttons[1]} on:click={log}>{count}</button>
|
Loading…
Reference in new issue