on GitHub" data-tooltip-id=":R1blcldtb:">v2.5.1·Edited Jan 31·
In this chapter, find an example of writing an integration test for a module using moduleIntegrationTestRunner from Medusa's Testing Framework.
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 "@medusajs/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})20 21jest.setTimeout(60 * 1000)
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 the following command to run your module integration tests:
test:integration:modules
script in package.json
, refer to the Medusa Testing Tools chapter.This runs your Medusa application and runs the tests available in any __tests__
directory under the src/modules
directory.