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
Hey! Thank you for this very useful repo.
I see that you've mentioned in a TODO on the Readme that you'll add more documentation testing web components. I'm struggling with this myself. I am already using the Testing Library, but it doesn't see to work properly with custom elements.
How do I import a custom element in Jest and use it? I'm not exporting everything as custom elements, and am using this recipe to only expose things that I need as web components instead of having all child components also be custom elements.
Now how do I import this and set it up in Jest? Please give me an idea on how to get started.
Thank you again!
The text was updated successfully, but these errors were encountered:
Hello and my pleasure! To be quite honest, I never got around to testing web components and don't anticipate that I will anytime soon.
I did some digging and I definitely see your troubles in finding resources around testing web components with Jest. I'm sorry I can't be of more help, and if you do find a solution, please feel free to post it here for others who might run into the same thing.
You don't have to test svelte's custom-elements as a special case. Just write test cases like you write for the normal svelte component. Use import name instead of custom tag name in test file (only exception when the component in question has nested child custom-elements).
In the Below example, Foo is a web-component with custom name - "component-foo" but i am using the "Foo" name only.
import { render } from "@testing-library/svelte";
import Foo from "../src/foo.svelte";
describe("Foo component", () => {
test("should render component correctly", () => {
const { container } = render(Foo, {
props: {
background: 'red',
name: 'Singh'
}
});
expect(container).toContainHTML('<body><div><h2 style="background: red;">Hello i am <p>Singh</p></h2></div></body>');
});
});
Uh oh!
There was an error while loading. Please reload this page.
Hey! Thank you for this very useful repo.
I see that you've mentioned in a TODO on the Readme that you'll add more documentation testing web components. I'm struggling with this myself. I am already using the Testing Library, but it doesn't see to work properly with custom elements.
How do I import a custom element in Jest and use it? I'm not exporting everything as custom elements, and am using this recipe to only expose things that I need as web components instead of having all child components also be custom elements.
Now how do I import this and set it up in Jest? Please give me an idea on how to get started.
Thank you again!
The text was updated successfully, but these errors were encountered: