testing convex
I am just getting the hang of vitest.
I read this https://docs.convex.dev/testing/convex-test and it seems like a pretty good guide to testing convex code in a convex project.
I am looking for guidance in testing the front end code in a convex project. Not sure how to go about it, how is the backend mocked?
convex-test | Convex Developer Hub
The convex-test library provides a mock implementation of the Convex backend
7 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
I think you'll just need to mock out the Convex stuff currently. Have not done it myself as I'm just doing e2e to cover frontend components currently.
Yeah I'd mock out the hooks like useQuery, make them do whatever you need them to do
That’s the perfect answer!!
Is it possible to test the backend functions as well. Using dependency injection
My 2 cents on testing -- use
convex-test
to write unit tests for your backend functions, use a fake of the ConvexReactClient
to test any complicated render logic in your UI, write a few e2e tests (e.g. against a staging project or against a preview deployment) to check that all the major flows work all the way through.
There's less test coverage on things that cross backend <-> UI (e.g. there could be a bug that's not caught by tests because the fake implementation for your backend functions used in UI tests doesn't match up with the actual implementation), but hopefully the majority of issues get caught by the unit tests.
Re: dependency injection + backend functions -- I kind of view convex-test
as something that dependency injects ctx
with something that gives you easy methods to set up data in your db
, set up auth
, etc.Thank you