{"id":18408914,"url":"https://github.com/vitest-dev/vitest-browser-svelte","last_synced_at":"2025-09-19T20:55:01.432Z","repository":{"id":252405646,"uuid":"839376038","full_name":"vitest-dev/vitest-browser-svelte","owner":"vitest-dev","description":"Render Svelte components in Vitest Browser Mode","archived":false,"fork":false,"pushed_at":"2025-08-05T13:01:11.000Z","size":322,"stargazers_count":40,"open_issues_count":3,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-05T15:05:05.003Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/vitest-browser-svelte","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vitest-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-08-07T13:38:07.000Z","updated_at":"2025-08-05T13:01:10.000Z","dependencies_parsed_at":"2024-08-09T15:26:22.821Z","dependency_job_id":"c8c35dd3-8f5e-4f18-9c5d-6abb17e4819f","html_url":"https://github.com/vitest-dev/vitest-browser-svelte","commit_stats":null,"previous_names":["vitest-dev/vitest-browser-svelte"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/vitest-dev/vitest-browser-svelte","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitest-dev%2Fvitest-browser-svelte","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitest-dev%2Fvitest-browser-svelte/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitest-dev%2Fvitest-browser-svelte/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitest-dev%2Fvitest-browser-svelte/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vitest-dev","download_url":"https://codeload.github.com/vitest-dev/vitest-browser-svelte/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitest-dev%2Fvitest-browser-svelte/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275998886,"owners_count":25567395,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-19T02:00:09.700Z","response_time":108,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T03:22:24.952Z","updated_at":"2025-09-19T20:55:01.425Z","avatar_url":"https://github.com/vitest-dev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vitest-browser-svelte\n\nRender Svelte components in Vitest Browser Mode. This library follows `testing-library` principles and exposes only [locators](https://vitest.dev/guide/browser/locators) and utilities that encourage you to write tests that closely resemble how your Svelte components are used.\n\nRequires `vitest` and `@vitest/browser` 2.1.0 or higher.\n\n```tsx\nimport { render } from 'vitest-browser-svelte'\nimport { expect, test } from 'vitest'\nimport Component from './Component.svelte'\n\ntest('counter button increments the count', async () =\u003e {\n  const screen = render(Component, {\n    initialCount: 1,\n  })\n\n  await screen.getByRole('button', { name: 'Increment' }).click()\n\n  await expect.element(screen.getByText('Count is 2')).toBeVisible()\n})\n```\n\n\u003e [!NOTE]\n\u003e This library doesn't expose or use `act`. Instead, you should use Vitest's locators and `expect.element` API that have [retry-ability mechanism](https://vitest.dev/guide/browser/assertion-api) baked in.\n\n`vitest-browser-svelte` also automatically injects `render` and `cleanup` methods on the `page`. Example:\n\n```ts\n// vitest.config.ts\nimport { defineConfig } from 'vitest/config'\n\nexport default defineConfig({\n  test: {\n    // if the types are not picked up, add `vitest-browser-svelte` to\n    // \"compilerOptions.types\" in your tsconfig or\n    // import `vitest-browser-svelte` manually so TypeScript can pick it up\n    setupFiles: ['vitest-browser-svelte'],\n    browser: {\n      name: 'chromium',\n      enabled: true,\n    },\n  },\n})\n```\n\n```tsx\nimport { page } from '@vitest/browser/context'\nimport Component from './Component.svelte'\n\ntest('counter button increments the count', async () =\u003e {\n  const screen = page.render(Component, {\n    initialCount: 1,\n  })\n\n  screen.cleanup()\n})\n```\n\nUnlike `@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-svelte/pure`.\n\n## Special thanks\n\n- Forked from [`@testing-library/svelte`](https://github.com/testing-library/svelte-testing-library)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitest-dev%2Fvitest-browser-svelte","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvitest-dev%2Fvitest-browser-svelte","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitest-dev%2Fvitest-browser-svelte/lists"}