Skip to content

invalid_snippet_arguments when rendering snippet using render function from @testing-library/svelte #15760

Open
@axel7083

Description

@axel7083

Describe the bug

Using vitest, and @testing-library/svelte in our codebase we were testing Snippets in different area using the render function from the testing library (see reproduction).

Recently with #15521 it has been added some extra validation when rendering Snippet. And our CI failed when dependabot tried to update svelte library.

The problem seems to be that the testing library calls the Snippet function with an empty object as argument, and fails at the following part of the code

for (let arg of args) {
if (typeof arg !== 'function') {
invalid_snippet_arguments();
}
}

Raising an invalid_snippet_arguments error.

Reproduction

Example.svelte

<script module>
  export { add };
</script>

{#snippet add(a, b)}
  {a} + {b} = {a + b}
{/snippet}

example.spec.ts

import '@testing-library/jest-dom/vitest';

import { render } from '@testing-library/svelte';
import { add } from './Example.svelte';
import { test } from 'vitest';

test('render snippet', () => {
  render(add);
});

Logs

Svelte error: invalid_snippet_arguments
A snippet function was passed invalid arguments. Snippets should only be instantiated via `{@render ...}`
https://svelte.dev/e/invalid_snippet_arguments

System Info

all platform (macos, ubuntu, windows)

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting submitterneeds a reproduction, or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions