Fix: properly destroy components after test case #304
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes issues around the use of svelte stores.
When components tested are controlled by svelte stores instead of props, they can end up in a long lived state (memory leak actually) where the components are still live in the DOM, and because of the way the cleanup has been done up until now by simply removing the DOM elements, they would still react to any svelte store changes happening in later tests. It further depended on what type of DOM manipulation the component was doing, if this was a problem or not.
The error being thrown is this:
A repro case with instructions, can be found here: https://github.com/royalrex/svelte-unit-test-bug
The solution was inspired by how Cypress v10.x, that includes built-in support for svelte component testing does their cleanup.
https://github.com/cypress-io/cypress/blob/develop/npm/svelte/src/mount.ts
Lines 25-29 + 74
Specifically was has been done is:
Alternative solution
" template, as that somehow removes the svelte component more thoroughly. I would still suggest to include this fix as well, as it's more clean and also tests the cleanup function executed inWhile testing this solution with styleOptions.html I found that it would be enough to just default to a standard '
onDestroy(() => {});
See other PR: Chore: Improve html template check (#305)