mirror of https://github.com/sveltejs/svelte
parent
bc050c34b7
commit
4d05ed1139
@ -0,0 +1,11 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ target, assert, logs }) {
|
||||||
|
const button = target.querySelector('button');
|
||||||
|
|
||||||
|
flushSync(() => button?.click());
|
||||||
|
assert.ok(logs[0].startsWith('set_context_after_init'));
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,19 @@
|
|||||||
|
<script>
|
||||||
|
import { setContext } from 'svelte';
|
||||||
|
|
||||||
|
let condition = $state(false);
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (condition) {
|
||||||
|
try {
|
||||||
|
setContext('potato', {});
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => condition = !condition}>
|
||||||
|
{condition}
|
||||||
|
</button>
|
Loading…
Reference in new issue