-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Given this component:
<script lang="ts">
let { children, ...props } = $props();
</script>
<button {...props}>
{@render children?.()}
</button>How can I test that children are being rendered?
I tried:
import { describe, expect, it, vi } from 'vitest';
import { render } from 'vitest-browser-svelte';
import { Button } from './index';
describe('Button Component', () => {
it('should render children text from default slot', () => {
const withChildren = render(Button, { children: () => 'Click me' });
const withoutChildren = render(Button, { children: () => '' });
expect(withChildren.container.innerHTML).not.toBe(withoutChildren.container.innerHTML);
expect(withChildren.container.textContent).toContain('Click me');
});
});but the first assertion fails with this error:
AssertionError: expected '<button><!----></button>' not to be '<button><!----></button>' // Object.is equality
I tried also not making the children as arrow functions in the test (render(Button, { children: 'Click me' });), but then I get TypeError: snippet2 is not a function
jprinaldi
Metadata
Metadata
Assignees
Labels
No labels