preactjs / signals

Manage state with style in every framework
https://preactjs.com/blog/introducing-signals/
MIT License
3.63k stars 88 forks source link

Asking and/or suggesting best practices on how to test Signals #521

Closed cafesanu closed 3 months ago

cafesanu commented 3 months ago

Hey there! Just wanted to start by saying I'm really liking the simplicity of this library – it's pretty cool.

I've been on a bit of a hunt online trying to find some best practices for testing signals, but no luck finding anything official. Got any tips or resources you could share?

We're in the process of checking out Jotai and Signals, considering a move away from Redux Toolkit. We're really into how straightforward Signals are, but hitting a bit of a snag with the lack of testing guidance.

Our packages for this exploration includes React 18, Testing Library, @preact/signals-react, and @preact/signals-react-transform.

Here’s what we’ve found and been thinking about:

In a nut shell, setting it up in redux or Jotai looks something like this:

// Pseudocode...
import { render } from "@testing-library/react";
...
render(
   <Provider fakeState={fakeState}>
      <ComponentToTest />
    <Provider />
);

Thank you! Love your project ❤❤❤