mirror of https://github.com/sveltejs/svelte
parent
ff0ccb8755
commit
7f6e5997db
@ -0,0 +1,9 @@
|
||||
<script>
|
||||
import { getContext } from 'svelte';
|
||||
|
||||
const value = getContext('key');
|
||||
const fn = getContext('fn');
|
||||
</script>
|
||||
|
||||
<div>{value}</div>
|
||||
<button on:click={() => fn('hello world')} />
|
||||
@ -0,0 +1,22 @@
|
||||
export default {
|
||||
async test({ assert, target, window }) {
|
||||
const Component = require('./Component.svelte').default;
|
||||
|
||||
const called = [];
|
||||
const component = new Component({
|
||||
target,
|
||||
context: {
|
||||
key: 'svelte',
|
||||
fn: (value) => called.push(value)
|
||||
}
|
||||
});
|
||||
assert.htmlEqual(target.innerHTML, '<div>svelte</div><button></button>');
|
||||
|
||||
const button = target.querySelector('button');
|
||||
await button.dispatchEvent(new window.MouseEvent('click'));
|
||||
|
||||
assert.deepEqual(called, ['hello world']);
|
||||
|
||||
component.$destroy();
|
||||
}
|
||||
};
|
||||
Loading…
Reference in new issue