testing-library / svelte-testing-library

:chipmunk: Simple and complete Svelte DOM testing utilities that encourage good testing practices
https://testing-library.com/docs/svelte-testing-library/intro
MIT License
620 stars 33 forks source link

fix: $destroy and createRoot are no more #328

Closed yanick closed 9 months ago

yanick commented 9 months ago

Feel free to ping me once this is in and I'll rebase #325 accordingly

I will! I'm still figuring out how to deal with $set. I'll push the code I have right now for shared lulz. It's not yet working, though.

mcous commented 9 months ago

I added the mount / unmount changes to #325 before you made this PR, which will at least unblock the majority of testing. I'm starting to think that either:

Either path feels like a bit of a bummer!

yanick commented 9 months ago
* `rerender` won't be supported in Svelte 5

  * Instead, the complexity is pushed to the user, who will need to do something like
    ```js
    // comp.test.svelte.js
    const props = $state({ name: 'hello' })
    render(Comp, { props })
    // ...
    act(() => (props.name = 'goodbye'))
    ```
  * This is how `solid-testing-library` operates

Yup, that's what I think as well. I'm trying to change the rerender test to use that ^^^ pattern, but for some reason it doesn't react to props.name = 'goodbye'. But I used a waitFor, not an act, so I'll try that.

* We'll need to introduce a build step into this library so we can use `$state` ourselves

I think we just need to change the name of the test file to be test.svelte.js for the compiler to do the right thing. I'll say this with more conviction once the test is passing. :-)

Right now my battle plan is

  1. find out the Way That Works with Svelte 5.
  2. see how that can fit with the previous versions of svelte. Worst case we might have to split things and have import {} from '@testing-library/svelte for the latest supported version and import {} from '@testing-library/svelte/svelteX for X that are legacy versions and upcoming versions.
  3. Depending on (2), organize the tests to cover the maximum without going insane.

So yeah, weeeeee, supporting several major versions is fun, fun, fun. :zany_face:

  * I actually don't know if this will work

Either path feels like a bit of a bummer!

yanick commented 9 months ago

@mcous This is not the patch we deserve, but probably the patch we need. I'm using the svelte/legacy API of svelte 5 as I could not make the runes work in the testing context yet. I've also skipped 2 tests for svelte 5 and happy-dom because they are failing in a weird way.

yanick commented 9 months ago

What's the value of it this approach over what's currently in #325, where pure.js continues to support both?

import {...} from 'svelte/legacy' goes boom for Svelte 3 that didn't have that package.

github-actions[bot] commented 9 months ago

:tada: This PR is included in version 4.2.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: