Skip to content

Commit 1241f43

Browse files
committed
test for context
1 parent 931b7f5 commit 1241f43

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

test/custom-elements/samples/nested/Counter.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<svelte:options tag="my-counter" />
22

33
<script>
4+
import { getContext } from "svelte";
5+
46
export let count = 0;
7+
8+
const context = getContext("context");
59
</script>
610

711
<slot />
812
<button on:click={() => (count += 1)}>count: {count}</button>
13+
<p>Context {context}</p>
914

1015
<style>
1116
button {

test/custom-elements/samples/nested/main.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<svelte:options tag="my-app" />
22

33
<script>
4+
import { setContext } from "svelte";
45
import Counter from "./Counter.svelte";
56
67
export let count;
78
export let counter;
9+
10+
setContext("context", "works");
811
</script>
912

1013
<Counter bind:count bind:this={counter}>

test/custom-elements/samples/nested/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ export default async function (target) {
88
const el = target.querySelector('my-app');
99
const button = el.shadowRoot.querySelector('button');
1010
const span = el.shadowRoot.querySelector('span');
11+
const p = el.shadowRoot.querySelector('p');
1112

1213
assert.equal(el.counter.count, 0);
1314
assert.equal(button.innerHTML, 'count: 0');
1415
assert.equal(span.innerHTML, 'slot 0');
16+
assert.equal(p.innerHTML, 'Context works');
1517
assert.equal(getComputedStyle(button).color, 'rgb(255, 0, 0)');
1618

1719
await button.dispatchEvent(new MouseEvent('click'));

0 commit comments

Comments
 (0)