Cloudflare 中文文档
Workers
Workers
编辑这个页面
跳转官方原文档
Set theme to dark (⇧+D)

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.

​​ Vitest integration

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.