Writing Unit Tests with Vitest
All versions of Nextbase Starter Kit come with Vitest installed. Vitest is a lightweight and fast testing framework that allows you to write unit tests for your application.
Vitest is configured in the
As you can see, the configuration file is quite simple. You can customize it according to your needs.
Vitest runs in
NODE_ENV=test mode. It also relies on
.env.test for environment variables.
All the test cases are written in the
Helper Function Test case example
This is an example of a test case for a helper function.
Using Vitest with GitHub Actions
You can easily integrate Vitest with GitHub Actions to run your tests automatically on every push or pull request. Here is a basic example of a GitHub Actions workflow:
Most SaaS solo developers or small teams write integration tests more, hence we only added Vitest setup and a dummy test case, but you can update the test suite as needed.