-
Notifications
You must be signed in to change notification settings - Fork 33
Svelte 5: rendering a component with a global transition causes an error #416
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
Comments
Svelte transitions now require the web animations API, which is not available in jsdom nor happy-dom, due to their lack of GUI. Since this is internal to Svelte, there's nothing (reasonable) for us to do in svelte-testing-library to resolve this. If you would like to run component-level tests of transitions, you either need to:
Alternatively, my preferred approach is to move my interesting logic to components and modules that don't involve transitions, test those components, and then pull those into components that only care about the transitions. From there, I don't bother writing additional component tests, because I can trust that Svelte tests its own transition logic For more context, see various posts in #284: |
An additional workaround could be to simply mock
|
Component tests tend to be fairly highly integrated - your test runs your own code, the Svelte runtime, the browser/fake DOM runtime, etc. all together. For that reason, I strongly recommend against mocking out "third-party" things like the Mocks are best reserved for situations where you completely isolate your code under test with those mocks, which is not possible with component tests |
# Motivation Svelte requires require the [web animations API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API), and neither [jsdom](https://github.com/jsdom/jsdom) nor [happy-dom](https://github.com/capricorn86/happy-dom) implements it. While in Gix-cmp or OISY we are able to apply some mocks in the configuration, this is insuffisent for the existing large test suite of NNS dapp for which many tests fail, when migrating to Svelte v5, with the error: > TypeError: Cannot set properties of undefined (setting 'onfinish') As suggested in one of the related issues (see linked below), we can overcome the problem by disabling animations in test mode. # References - testing-library/svelte-testing-library#284 (comment) - testing-library/svelte-testing-library#416 # CI issues - https://github.com/dfinity/nns-dapp/actions/runs/13129931873/job/36632946426 # Changes - Implement utils for fade, fly and scale that returns an empty transition configuration for test mode - Expose utils to make to re-usable by consumers as well # Tests Errors do not happen anymore in NNS dapp - Svelte v5 wip branch running in the CI. - https://github.com/dfinity/nns-dapp/actions/runs/13131104521/job/36636304026?pr=6020 --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Problem
During migration from Svelte 4 to Svelte 5 I am getting error when I try to render component with
global
transition.If I remove the global transition from
<p in:slide|global>
to<p in:slide>
, it no longer throws any error.Reproduction
Test
Components
Error log
Package versions
The text was updated successfully, but these errors were encountered: