#Unit testing/E2E testing
10 messages · Page 1 of 1 (latest)
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 too
Sweet 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
import { expect, it, vi } from "vitest";
import { sendMeatLorumIpsum } from "./sendMessage";
it("sendMeatLorumIpsum should should insert a long message", async () => {
const ctx = { runMutation: vi.fn() };
await sendMeatLorumIpsum(ctx);
expect(ctx.runMutation.mock.calls.length === 1);
expect(ctx.runMutation.mock.calls[0][0]).toEqual("sendMessage");
expect(ctx.runMutation.mock.calls[0][1].author).toEqual("baconipsum.com");
expect(ctx.runMutation.mock.calls[0][1].body.length > 100).toBeTruthy();
});
Sweet thank you will take a look
not using Vite so unfortunately not Vitest
You don't need to be using Vite to use Vitest.