Skip to content

Commit 739b511

Browse files
committed
tweak test
1 parent 3dac3e7 commit 739b511

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
import { expect, vi } from 'vitest';
21
import { test } from '../../test';
32
import { flushSync } from 'svelte';
43

5-
const trackBranch = vi.fn();
6-
74
export default test({
85
mode: ['client'],
9-
props: { trackBranch: trackBranch },
10-
async test({ target }) {
6+
async test({ target, assert, logs }) {
117
const button = target.querySelector('button');
128

13-
flushSync(() => button?.click());
14-
flushSync(() => button?.click());
15-
flushSync(() => button?.click());
16-
flushSync(() => button?.click());
9+
button?.click();
10+
flushSync();
11+
button?.click();
12+
flushSync();
13+
button?.click();
14+
flushSync();
15+
button?.click();
16+
flushSync();
1717

18-
expect(trackBranch).toHaveBeenCalledWith('one');
19-
expect(trackBranch).toHaveBeenCalledWith('two');
20-
expect(trackBranch).not.toHaveBeenCalledWith('else');
18+
assert.deepEqual(logs, ['two', 'one', 'two', 'one', 'two']);
2119
}
2220
});
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<script lang="ts">
2-
const { trackBranch }:{ trackBranch: (branch:string)=>void } = $props();
3-
42
let b = $state(false);
53
let v = $state("two");
64
@@ -12,9 +10,9 @@
1210
<button onclick={() => b = !b}>Trigger</button>
1311

1412
{#if v === "one"}
15-
<div>if1 matched! {trackBranch('one')}</div>
13+
<div>if1 matched! {console.log('one')}</div>
1614
{:else if v === "two"}
17-
<div>if2 matched! {trackBranch('two')}</div>
15+
<div>if2 matched! {console.log('two')}</div>
1816
{:else}
19-
<div>nothing matched {trackBranch('else')}</div>
17+
<div>nothing matched {console.log('else')}</div>
2018
{/if}

0 commit comments

Comments
 (0)