Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
vitest-browser-svelte
Advanced tools
Render Svelte components in Vitest Browser Mode. This library follows testing-library
principles and exposes only locators and utilities that encourage you to write tests that closely resemble how your Svelte components are used.
Requires vitest
and @vitest/browser
2.1.0 or higher.
import { render } from 'vitest-browser-svelte'
import { expect, test } from 'vitest'
import Component from './Component.svelte'
test('counter button increments the count', async () => {
const screen = render(Component, {
initialCount: 1,
})
await screen.getByRole('button', { name: 'Increment' }).click()
await expect.element(screen.getByText('Count is 2')).toBeVisible()
})
[!NOTE] This library doesn't expose or use
act
. Instead, you should use Vitest's locators andexpect.element
API that have retry-ability mechanism baked in.
vitest-browser-svelte
also automatically injects render
and cleanup
methods on the page
. Example:
// vitest.config.ts
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
// if the types are not picked up, add `vitest-browser-svelte` to
// "compilerOptions.types" in your tsconfig or
// import `vitest-browser-svelte` manually so TypeScript can pick it up
setupFiles: ['vitest-browser-svelte'],
browser: {
name: 'chromium',
enabled: true,
},
},
})
import { page } from '@vitest/browser/context'
import Component from './Component.svelte'
test('counter button increments the count', async () => {
const screen = page.render(Component, {
initialCount: 1,
})
screen.cleanup()
})
Unlike @testing-library/svelte
, vitest-browser-svelte
cleans up the component before the test starts instead of after, so you can see the rendered result in your UI. To avoid auto-cleanup, import the render
function from vitest-browser-vue/pure
.
@testing-library/svelte
FAQs
Render Svelte components in Vitest Browser Mode
We found that vitest-browser-svelte demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.