pull/11265/head
Rich Harris 2 years ago
parent 1d47e69d89
commit 0ce879837b

@ -4,5 +4,7 @@ import { unmount } from 'svelte';
export default test({
test({ component }) {
unmount(component.l1);
}
},
warnings: ['Tried to unmount a component that was not mounted.']
});

@ -5,5 +5,10 @@ export default test({
test({ component }) {
unmount(component);
unmount(component);
}
},
warnings: [
'Tried to unmount a component that was not mounted.',
'Tried to unmount a component that was not mounted.'
]
});

@ -1,6 +1,6 @@
<script>
import { onDestroy } from 'svelte';
import { onDestroy } from 'svelte';
onDestroy(() => {
console.log('destroy');

@ -1,30 +1,14 @@
import { test } from '../../test';
/**
* @type {{ (...data: any[]): void; (message?: any, ...optionalParams: any[]): void; (...data: any[]): void; (message?: any, ...optionalParams: any[]): void; }}
*/
let log;
export default test({
html: `
<button>destroy component</button>
`,
before_test() {
log = console.log;
},
after_test() {
console.log = log;
},
async test({ assert, target, window }) {
async test({ assert, target, window, logs }) {
const button = target.querySelector('button');
const event = new window.MouseEvent('click');
/**
* @type {any[]}
*/
const messages = [];
console.log = (msg) => messages.push(msg);
// @ts-ignore
await button.dispatchEvent(event);
assert.htmlEqual(
@ -33,6 +17,6 @@ export default test({
<button>destroy component</button>
`
);
assert.deepEqual(messages, ['destroy']);
assert.deepEqual(logs, ['destroy']);
}
});

@ -3,6 +3,6 @@
let active = true;
</script>
<button on:click='{() => active = false }'>destroy component</button>
<button on:click={() => active = false }>destroy component</button>
<svelte:component this={active ? Empty : null} />

@ -299,13 +299,6 @@ async function run_test_variant(
assert.fail('Expected a runtime error');
}
if (config.warnings) {
assert.deepEqual(warnings, config.warnings);
} else if (warnings.length) {
unintended_error = true;
assert.fail('Received unexpected warnings');
}
if (config.html) {
flushSync();
assert_html_equal_with_options(target.innerHTML, config.html, {
@ -345,6 +338,14 @@ async function run_test_variant(
} finally {
instance.$destroy();
if (config.warnings) {
assert.deepEqual(warnings, config.warnings);
} else if (warnings.length && console.warn === warn) {
unintended_error = true;
warn.apply(console, warnings);
assert.fail('Received unexpected warnings');
}
assert_html_equal(
target.innerHTML,
'',

@ -11,7 +11,7 @@
{/each}
{#each items as item (item.name)}
<Item {item} {items} onclick={() => {console.log('hello'); item.name = item.name + '+'}} />
<Item {item} {items} onclick={() => item.name = item.name + '+'} />
{/each}
{#each items as item}

Loading…
Cancel
Save