A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://stackoverflow.com/questions/75435234/how-to-test-svelte-component-props-with-vitest below:

unit testing - How to test Svelte component props with Vitest?

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 instance unless 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?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4