Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
1 vote
0 answers
56 views

Unit test when there is style on the component

I'm checking out Svelte 5 and I have this simple component <script lang="ts"> let { name }: { name: string; } = $props(); </script> <h1> ...
Hey's user avatar
  • 197
0 votes
1 answer
110 views

Got error "Function called outside component initialization" when testing Svelte component with Vitest

I want to test the following Svelte component with Vitest: <script context="module"> import {push} from 'svelte-spa-router' import {onDestroy} from 'svelte' let time = ...
Jan Seipel's user avatar
0 votes
0 answers
255 views

How can I mock API / Module and test this svelte Component

Within my src/lib/apis directory I have a file named data.ts which contains the below code: export async function getData(searchInput: string) { return fetch('https://dummyjson.com/products', { ...
Sameer's user avatar
  • 1
0 votes
1 answer
2k views

How to create unit test in Svelte using Vitest?

I have created a skeleton project using Sveltekit. I would like to create unit tests for three different files. One of the first files is the index.js under the src/lib folder: export function add(a, ...
Péter Szilvási's user avatar
5 votes
1 answer
1k views

vitest and svelte component's onMount

I'm trying to use Svelte to create a simple reactive component. The component loads data from an api server onMount and updates a reactive value (which updates a html element). I have a simple vitest ...
Sandeep Chayapathi's user avatar
8 votes
2 answers
2k views

How can I reset the jsdom instance when using vitest in order to test a History-based router?

I'd like to do some integration testing of my svelte + page.js-based router using vitest, but I'm running into an issue where the jsdom instance only updates correctly once per test file. In the ...
jrh's user avatar
  • 4,193
11 votes
2 answers
9k views

vitest crypto.randomUUID() is not a function

vite.config.ts import { sveltekit } from '@sveltejs/kit/vite'; const config = { plugins: [sveltekit()], test: { include: ['**/*.spec.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], ...
Lun's user avatar
  • 1,091