@confect/test wraps convex-test with Effect-native APIs. It provides a TestConfect service that lets you call your Confect functions using refs, run arbitrary mutation-context code for test setup, and test with user identities.
Installation
Setup
Create aTestConfect.ts file that configures the test layer with your database schema and Convex modules.
test/TestConfect.ts
TestConfect layer is constructed, a new test database is created. If you want a clean database for each test, provide the layer on a per-test basis (as shown below). If you want to share state across tests in a describe block, you can provide the layer at a higher scope instead.
Writing tests
Use@effect/vitest’s it.effect to write effectful tests. Yield TestConfect from the service, then call your functions using refs.
test/notes.test.ts
Calling functions
TestConfect provides query, mutation, and action methods that accept a ref and args, returning an Effect with the decoded result.
Running setup code
Userun to execute arbitrary code with mutation-context services (like DatabaseWriter) for test setup. When the handler returns a value, pass a Schema as the second argument for decoding.
void, the second argument can be omitted.
Testing with user identity
UsewithIdentity to scope function calls to a specific user identity.
Testing HTTP endpoints
Usefetch to test your HTTP API endpoints.
Testing scheduled functions
TestConfect provides helpers for advancing scheduled functions in tests.