Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1655

How to test Svelte component props with Vitest?

$
0
0

I want to test the props of a Svelte component with Vitest.

Component:

<script>  export let foo</script><div>{foo}</div>

Test:

const { component } = render(MyComponent, { foo: 'bar' })expect(component.foo).toBe('bar')

When I run this test, I get the following error:

Props cannot be read directly from the component instanceunless compiling with 'accessors: true' or '<svelte:options accessors/>'

According to this post, I should pass accessors: true to the render() function:

const { component } = render(MyComponent, { accessors: true })

However, this doesn't work either and I keep getting the same error.

How can I test Svelte component props?


Viewing all articles
Browse latest Browse all 1655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>