Unit testing
In a Workers context, a unit test imports and directly calls functions from your Worker. After calling the functions, the unit test then asserts on the functions' return values. For example, consider you have the following Worker:
An example unit test for the above Worker may look like the following:
This test only verifies that the add
function is returning the correct value, but does not test the Worker itself like an integration test would.
The recommended way to unit test your Workers is by using the Workers Vitest integration. For more information on features, as well as installation and setup instructions, refer to the Vitest integration Get Started guide.
- Recipes - Examples of unit tests using the Workers Vitest integration.