You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to render a component, set the test conditions and then call something like expect(RenderedComponent).toRenderSnippet(...) or .not.toRenderSnippet(...)?
For example
it('should render the snippet if conditions are met',async()=>{// this would be a new functions that auto-fills the children/props that are Snippet for exampleconst{renderedComponent}=renderWithMockedSnippets(MyComponent);// here the consumer sets the conditions to render the snippet (if it is conditional)
........expect(renderedComponent).toHaveSnippet(...)})
The text was updated successfully, but these errors were encountered:
AntonioVentilii
changed the title
Feature Request: built in function to check if a slot is rendered
Feature Request: built in function to check if a snippet is rendered
Apr 15, 2025
Create a wrapper component around your component under test, passing all non-snippet props along
In the wrapper component, set the snippet to a DOM element with a data-testid attribute
Render the wrapper component, setting or updating the props as necessary to render (or hide) the snippet
Check if getByTestId('your-snippet-test-id') is in the document or not
Snippets are hard to create generic fixtures for, due to fundamental limitations with how Svelte works, so (for the time being) the best approach is "one wrapper component per test," unfortunately.
In terms of adding new methods to expect - that's outside the scope of the @testing-library/svelte library. You can add your own - see the vitest docs - or check out testing-library/jest-dom if you're curious to see how they do it
Hello,
Is there a way to render a component, set the test conditions and then call something like
expect(RenderedComponent).toRenderSnippet(...)
or.not.toRenderSnippet(...)
?For example
The text was updated successfully, but these errors were encountered: