Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/__tests__/mount.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, render, screen } from '@testing-library/svelte'
import { render, screen } from '@testing-library/svelte'
import { describe, expect, test, vi } from 'vitest'

import Mounter from './fixtures/Mounter.svelte'
Expand All @@ -14,20 +14,17 @@ describe('mount and destroy', () => {
const content = screen.getByRole('button')

expect(content).toBeInTheDocument()
await act()
expect(onMounted).toHaveBeenCalledTimes(1)
})

test('component is destroyed', async () => {
const { unmount } = renderSubject()

await act()
unmount()

const content = screen.queryByRole('button')

expect(content).not.toBeInTheDocument()
await act()
expect(onDestroyed).toHaveBeenCalledTimes(1)
})
})
3 changes: 2 additions & 1 deletion src/core/modern.svelte.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const mount = (Component, options) => {
const props = $state(options.props ?? {})
const component = Svelte.mount(Component, { ...options, props })

Svelte.flushSync()
propsByComponent.set(component, props)

return component
Expand All @@ -34,7 +35,7 @@ const mount = (Component, options) => {
/** Remove the component from the DOM. */
const unmount = (component) => {
propsByComponent.delete(component)
Svelte.unmount(component)
Svelte.flushSync(() => Svelte.unmount(component))
}

/**
Expand Down