-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed tests don't remove element from DOM #190
Comments
Hi, Import describe("size", () => {
["compact", "foo"].forEach(size => {
it(`should render ${size} size`, () => {
render(GoAButton, { size });
const button = screen.findByRole("button");
expect(button).toBeTruthy();
expect(button.className).toContain(size);
});
});
}); Pulling queries directly out of the render should also be avoided. There are certain circumstances where you will retrieve a query function that is unusable. |
Hello, I am also seeing an issue with this. It appears to happen with |
We're you able to find any workaround for your issue @austinworks ? |
Seems like a legit screen pollution issue, even happens when using the best I've been able to figure out is wrapping the target version of the render in an identifier and then using queries within the test to scope it. I added a branch to demo this: https://github.com/austinworks/render-problem-example/blob/selector_workaround/src/example/CompTest.test.ts |
@yanick I dug into this and can confirm that this is, indeed, a cleanup bug in svelte-testing-library. It is difficult to reproduce in our own test suite due to #222, but can be done with some of the trickery mentioned in that thread.
svelte-testing-library/src/pure.js Line 26 in c0ff791
svelte-testing-library/src/pure.js Lines 57 to 60 in c0ff791
svelte-testing-library/src/pure.js Line 62 in c0ff791
svelte-testing-library/src/pure.js Lines 108 to 110 in c0ff791
If the component throws in step (2) (or internals throw between steps (1) and (2)), the For fixing the issues, there's a lot of suspect-looking stuff going on in the code in question. I think this might be a case of "simplify to fix"
|
Thanks for looking into this. |
I think that will be alleviated when we merge #210, as rerender will no longer destroy the component, and will be simplified by a lot.
I have to think a little more before I say anything silly, but perhaps we might do something as simple as add a |
Nice, yeah that should help!
Yeah, something like this feels pretty resilient. I was planning to peep the React and Vue libs to see what they do and check if there's an alignment opportunity |
🎉 This issue has been resolved in version 4.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Because my svelte component is being compiled to a web component I need to do some additional validation on passed in attributes within the
onMount
function. If I throw an exception for an invalid attribute type the element isn't removed from the DOM and all later tests then fail due to thefindByRole
method then finding more than one element.Errors raised
I have tried calling the
cleanup
method in anafterEach
, but that didn't change anything.The text was updated successfully, but these errors were encountered: