- Get Started
- Framework
- Get Started
- Framework
8.2. Write Integration Tests
In this chapter, you'll learn about the localProtoIntegrationTestRunner
utility function used to write integration tests.
localProtoIntegrationTestRunner Utility#
The localProtoIntegrationTestRunner
utility function is provided by the @localprotojs/test-utils
package to create integration tests in your Local Protocol project. It runs a full Local Protocol application, allowing you test API routes, workflows, or other customizations.
For example:
The localProtoIntegrationTestRunner
function accepts an object as a parameter. The object has a required property testSuite
.
testSuite
's value is a function that defines the tests to run. The function accepts as a parameter an object that has the following properties:
api
: a set of utility methods used to send requests to the Local Protocol application. It has the following methods:get
: Send aGET
request to an API route.post
: Send aPOST
request to an API route.delete
: Send aDELETE
request to an API route.
getContainer
: a function that retrieves the Local Protocol Container. Use thegetContainer().resolve
method to resolve resources from the Local Protocol Container.
The tests in the testSuite
function are written using Jest.
Run Tests#
Run the following command to run your tests:
This runs your Local Protocol application and runs the tests available under the src/integrations/http
directory.
Database Used in Tests#
The localProtoIntegrationTestRunner
function creates a database with a random name before running the tests. Then, it drops that database after all the tests end.
Example Integration Tests#
The next chapters provide examples of writing integration tests for API routes and workflows.