
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
@testing-library/svelte-core
Advanced tools
Core rendering and cleanup logic for Svelte testing utilities.
Do you want to build your own Svelte testing library? You may want to use our rendering core, which abstracts away differences in Svelte versions to provide a simple API to render Svelte components into the document and clean them up afterwards
import { beforeEach } from 'vitest'
import * as SvelteCore from '@testing-library/svelte-core'
import { bindQueries, type Screen } from './bring-your-own-queries.js'
beforeEach(() => {
SvelteCore.cleanup()
})
export interface RenderResult<
C extends SvelteCore.Component,
> extends SvelteCore.RenderResult<C> {
screen: Screen
}
export const render = <C extends SvelteCore.Component>(
Component: SvelteCore.ComponentImport<C>,
options: SvelteCore.ComponentOptions<C>
): RenderResult<C> => {
const renderResult = SvelteCore.render(Component, options)
const screen = bindQueries(baseElement)
return { screen, ...renderResult }
}
renderSet up the document and mount a component into that document.
const { baseElement, container, component, unmount, rerender } = render(
Component,
componentOptions,
setupOptions
)
| Argument | Type | Description |
|---|---|---|
Component | Svelte component | An imported Svelte component |
componentOptions | Props or partial mount options | Options for how the component will be mounted |
setupOptions | { baseElement?: HTMLElement } | Optionally override baseElement |
| Result | Type | Description | Default |
|---|---|---|---|
baseElement | HTMLElement | The base element | document.body |
container | HTMLElement | The component's immediate parent element | <div> appended to document.body |
component | component exports | The component's exports from mount | N/A |
rerender | (props: Partial<Props>) => Promise<void> | Update the component's props | N/A |
unmount | () => void | Unmount the component from the document | N/A |
[!TIP] Calling
renderis equivalent to callingsetupfollowed bymountconst { baseElement, container, mountOptions } = setup( componentOptions, setupOptions ) const { component, rerender, unmount } = mount(Component, mountOptions)
setupValidate options and prepare document elements for rendering.
const { baseElement, target, mountOptions } = setup(options, renderOptions)
| Argument | Type | Description |
|---|---|---|
componentOptions | Props or partial mount options | Options for how the component will be mounted |
setupOptions | { baseElement?: HTMLElement } | Optionally override baseElement |
| Result | Type | Description | Default |
|---|---|---|---|
baseElement | HTMLElement | The base element | document.body |
container | HTMLElement | The component's immediate parent element | <div> appended to document.body |
mountOptions | mount options | Validated options to pass to mount | { target, props: {} } |
mountMount a Svelte component into the document.
const { component, unmount, rerender } = mount(Component, options)
| Argument | Type | Description |
|---|---|---|
Component | Svelte component | An imported Svelte component |
mountOptions | component options | Options to pass to Svelte's mount function |
| Result | Type | Description |
|---|---|---|
component | component exports | The component's exports from mount |
unmount | () => void | Unmount the component from the document |
rerender | (props: Partial<Props>) => Promise<void> | Update the component's props |
cleanupCleanup rendered components and added elements. Call this when your tests are over.
cleanup()
addCleanupTaskAdd a custom cleanup task to be called with cleanup()
addCleanupTask(() => {
// ...reset something
})
removeCleanupTaskRemove a cleanup task from cleanup(). Useful if a cleanup task can only be run
once and may be run outside of cleanup
const customCleanup = () => {
// ...reset something
}
addCleanupTask(customCleanup)
const manuallyCleanupEarly = () => {
customCleanup()
removeCleanupTask(customCleanup)
}
This module exports various utility types from
@testing-library/svelte-core/types. They adapt to whatever Svelte version is
installed, and can be used to get type signatures for imported components,
props, exports, etc.
See ./types.d.ts for the full list of available types.
FAQs
Core rendering and cleanup logic for Svelte testing utilities.
The npm package @testing-library/svelte-core receives a total of 26 weekly downloads. As such, @testing-library/svelte-core popularity was classified as not popular.
We found that @testing-library/svelte-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 16 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.