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:
We know mocks are an option, but we're trying to steer clear of them as much as possible, keeping in line with Testing Library's spirit.
The simplest method seems to be just tweaking the signal directly, like theSignal.value = "something", but it ends up affecting all tests in that file. We can reset the signal with a beforeEach for each test, but this seems cumbersome and not scalable. We are curious if there's a better way to handle it.
Not here to compare libraries, just sharing some thoughts:
Jotai has this Provider setup for testing, detailed nicely here: Jotai Testing Guide, which is super handy for plugging in whatever values and letting Jotai do its thing.
Redux Toolkit uses a similar approach with its Provider.
In a nut shell, setting it up in redux or Jotai looks something like this:
Wondering if there is anything similar in this library? Or even if not, wondering what is the official recommendation
More that an answer here on how to do it for my case, I would love an official way on how to do this, regarless of how similar or different it is compared with the examples I gave.
If there is no official way or this has not been thought, I would like to suggest a similar approach to the Provider. This way, each test is completely isolated white having an easy way to pass testing values to atoms.
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:
theSignal.value = "something"
, but it ends up affecting all tests in that file. We can reset the signal with abeforeEach
for each test, but this seems cumbersome and not scalable. We are curious if there's a better way to handle it.Provider
.In a nut shell, setting it up in redux or Jotai looks something like this:
Thank you! Love your project ❤❤❤