How to test actions?
I'm using vitest in a SolidStart project.
I'm trying to create tests for an action and haven't been able to figure it out or find any info on it.
My current guess is that I need to automate/UI Test a form in a route, but thought I would ask before using more time by guessing.
I have never done UI testing and wishing there was a way to do this in pure JS. But
useAction
only works in a Route so I'm guessing creating a route with a form is the only way?2 Replies
This is what I came up with:
As an alternative. If you extract the function inside the action you could test this and assume it'll work with the action as well.
In my example I test the whole cycle of
query -> action -> revalidate the query
.
I don't thinks its to crazy UI testing.That was hugely helpful. There were a couple of things I hadn't thought about
- Can't use
https://github.com/klequis/ex-madaxen-query-actions.
<FileRoutes>
- UI isn't actually rendered
I think it would be good to add your code to the official example: https://github.com/solidjs/solid-start/tree/main/examples/with-vitest ?
Here it is as an example project with the way you did it and a variation moving the db and query/action to /lib
to simulate the project I'm working on. I originally tried the latter with <FileRoutes>
and got a bunch of very strange errors.https://github.com/klequis/ex-madaxen-query-actions.