-
Notifications
You must be signed in to change notification settings - Fork 33
fix: remove DOM elements even if component creation fails #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { describe, expect, test, vi } from 'vitest' | ||
|
||
import { cleanup, render } from '..' | ||
import Mounter from './fixtures/Mounter.svelte' | ||
|
||
const onMounted = vi.fn() | ||
const onDestroyed = vi.fn() | ||
const renderSubject = () => render(Mounter, { onMounted, onDestroyed }) | ||
|
||
describe('cleanup', () => { | ||
test('cleanup unmounts component and deletes element', () => { | ||
renderSubject() | ||
|
||
cleanup() | ||
|
||
expect(onDestroyed).toHaveBeenCalledOnce() | ||
expect(document.body).toBeEmptyDOMElement() | ||
}) | ||
|
||
test('cleanup handles unexpected errors during mount', () => { | ||
onMounted.mockImplementation(() => { | ||
throw new Error('oh no!') | ||
}) | ||
|
||
expect(renderSubject).toThrowError() | ||
cleanup() | ||
|
||
expect(document.body).toBeEmptyDOMElement() | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { defineConfig } from 'vite' | |
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig(({ mode }) => ({ | ||
plugins: [svelte()], | ||
plugins: [svelte({ hot: false })], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I disabled HMR because with it enabled, the new test that throws an error in I think there's something here to add to the documented setup, but vite-plugin-svelte's default setting for |
||
resolve: { | ||
// Ensure `browser` exports are used in tests | ||
// Vitest prefers modules' `node` export by default | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This snapshot removal due to disabling HMR in our test suite