Unit testing/E2E testing
Pulse check:
How are people generally writing unit/e2e tests for convex actions?
I've been exploring a few options and wanted to browse other approaches (not using Vite so unfortunately not Vitest).
6 Replies
For unit tests, Node.js actions can be run locally in Node.js — so just importing them and running them with a mocked context as the first argument (e.g. jest.fn() for runMutation, scheduling, etc.) is a path I've used some.
non-
"use node";
actions are also often runnable locally, I've tested these in Node.js too, but there are cases where the difference in environment could matter, similar to testing browser code in Node.js.
re Vitest you don't need to be using Vite to use it, but Jest should be fine tooSweet sounds good thanks. Will give those a shot.
Are there any code snippets you could share?
Been out all weekend, sorry for the delay! Here's a quick example: https://github.com/thomasballinger/convex-tutorial-test/compare/tests
That's a mutation, let me add an action real quick
Just updated, the interesting bit is
Sweet thank you will take a look
not using Vite so unfortunately not VitestYou don't need to be using Vite to use Vitest.
been trying out the new tests, working well so far!