Skip to content

Commit 0341e0b

Browse files
author
hackape
committed
chore: add testcases
1 parent 1cc1280 commit 0341e0b

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script>
2+
export let testcase;
3+
export let value = { foo: 'kid' };
4+
5+
if (testcase === 'init_update') {
6+
value = { foo: 'kid' }
7+
}
8+
9+
$: if (testcase === 'reactive_update') {
10+
value = { foo: 'kid' }
11+
}
12+
13+
$: if (testcase === 'reactive_mutate') {
14+
value.foo = 'kid'
15+
}
16+
17+
export let updates = [];
18+
$: updates = [...updates, value];
19+
</script>
20+
21+
<div>child: {value?.foo} | updates: {updates.length}</div>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
import Child from './Child.svelte';
3+
export let child;
4+
5+
export let testcase;
6+
export let value;
7+
export let updates = [];
8+
$: updates = [...updates, value];
9+
</script>
10+
11+
<div>parent: {value?.foo} | updates: {updates.length}</div>
12+
<Child bind:value bind:this={child} {testcase} />
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
export default {
2+
get props() {
3+
return {
4+
configs: [
5+
{ testcase: 'parent_override_child_default', value: { foo: 'mon' } },
6+
{ testcase: 'child_default_populate_parent', value: undefined },
7+
{ testcase: 'reactive_update', value: { foo: 'mon' } },
8+
{ testcase: 'reactive_mutate', value: { foo: 'mon' } },
9+
{ testcase: 'init_update', value: { foo: 'mon' } }
10+
]
11+
};
12+
},
13+
14+
async test({ assert, component }) {
15+
const parents = component.parents;
16+
17+
// first testcase should update once
18+
// the rest should update twice
19+
let p;
20+
p = parents['parent_override_child_default'];
21+
assert.deepEqual(p.value, { foo: 'mon' });
22+
assert.equal(p.updates.length, 1);
23+
24+
p = parents['child_default_populate_parent'];
25+
assert.deepEqual(p.value, { foo: 'kid' });
26+
assert.equal(p.updates.length, 2);
27+
28+
p = parents['reactive_update'];
29+
assert.deepEqual(p.value, { foo: 'kid' });
30+
assert.equal(p.updates.length, 2);
31+
32+
p = parents['reactive_mutate'];
33+
assert.deepEqual(p.value, { foo: 'kid' });
34+
assert.equal(p.updates.length, 2);
35+
36+
p = parents['init_update'];
37+
assert.deepEqual(p.value, { foo: 'kid' });
38+
assert.equal(p.updates.length, 2);
39+
}
40+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
import Parent from './Parent.svelte';
3+
export let configs = [];
4+
export let parents = {};
5+
</script>
6+
7+
{#each configs as config}
8+
<Parent bind:this={parents[config.testcase]} value={config.value} testcase={config.testcase} />
9+
{/each}

0 commit comments

Comments
 (0)