- Get Started
 - Framework
 
Menu
- Get Started
 - Framework
 
8.3.1. Example: Integration Tests for a Module
In this chapter, find an example of writing an integration test for a module using the moduleIntegrationTestRunner utility function.
Write Integration Test for Module#
Consider a hello module with a HelloModuleService that has a getMessage method:
To create an integration test for the method, create the file src/modules/hello/__tests__/service.spec.ts with the following content:
1import { moduleIntegrationTestRunner } from "@localprotojs/test-utils"2import { HELLO_MODULE } from ".."3import HelloModuleService from "../service"4import MyCustom from "../models/my-custom"5 6moduleIntegrationTestRunner<HelloModuleService>({7 moduleName: HELLO_MODULE,8 moduleModels: [MyCustom],9 resolve: "./src/modules/hello",10 testSuite: ({ service }) => {11 describe("HelloModuleService", () => {12 it("says hello world", () => {13 const message = service.getMessage()14 15 expect(message).toEqual("Hello, World!")16 })17 })18 },19})
You use the moduleIntegrationTestRunner function to add tests for the hello module. You have one test that passes if the getMessage method returns the "Hello, World!" string.
Run Test#
Run the following command to run your module integration tests:
Tip: If you don't have a  test:modules  script in  package.json , refer to the  Local Protocol Testing Tools chapter .
This runs your Local Protocol application and runs the tests available in any __tests__ directory under the src/modules directory.
Was this chapter helpful?