-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Svelte v5-next support (#321)
* fix: remove DOM elements even if component creation fails Fixes #190 * feat: add Svelte v5-next support
- Loading branch information
Showing
12 changed files
with
210 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { describe, expect, test, vi } from 'vitest' | ||
|
||
import { act, cleanup, render } from '..' | ||
import Mounter from './fixtures/Mounter.svelte' | ||
|
||
const onExecuted = vi.fn() | ||
const onDestroyed = vi.fn() | ||
const renderSubject = () => render(Mounter, { onExecuted, onDestroyed }) | ||
|
||
describe('cleanup', () => { | ||
test('cleanup deletes element', async () => { | ||
renderSubject() | ||
cleanup() | ||
|
||
expect(document.body).toBeEmptyDOMElement() | ||
}) | ||
|
||
test('cleanup unmounts component', async () => { | ||
await act(renderSubject) | ||
cleanup() | ||
|
||
expect(onDestroyed).toHaveBeenCalledOnce() | ||
}) | ||
|
||
test('cleanup handles unexpected errors during mount', () => { | ||
onExecuted.mockImplementation(() => { | ||
throw new Error('oh no!') | ||
}) | ||
|
||
expect(renderSubject).toThrowError() | ||
cleanup() | ||
|
||
expect(document.body).toBeEmptyDOMElement() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
<script> | ||
import { onDestroy,onMount } from 'svelte' | ||
import { onDestroy, onMount } from 'svelte' | ||
export let onMounted | ||
export let onDestroyed | ||
export let onExecuted = undefined | ||
export let onMounted = undefined | ||
export let onDestroyed = undefined | ||
onMount(() => onMounted()) | ||
onDestroy(() => onDestroyed()) | ||
onExecuted?.() | ||
onMount(() => { | ||
onMounted?.() | ||
}) | ||
onDestroy(() => { | ||
onDestroyed?.() | ||
}) | ||
</script> | ||
<button /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
<script> | ||
import { getContext, onMount } from 'svelte' | ||
import { onDestroy, onMount } from 'svelte' | ||
export let name | ||
export let onExecuted = undefined | ||
export let onMounted = undefined | ||
export let onDestroyed = undefined | ||
const mountCounter = getContext('mountCounter') | ||
export let name = '' | ||
onMount(() => { | ||
mountCounter.update((i) => i + 1) | ||
}) | ||
</script> | ||
onExecuted?.() | ||
onMount(() => onMounted?.()) | ||
<h1 data-testid="test">Hello {name}!</h1> | ||
onDestroy(() => onDestroyed?.()) | ||
</script> | ||
<div data-testid="mount-counter">{$mountCounter}</div> | ||
<div data-testid="test">Hello {name}!</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.