Skip to content

[TEST] How to assert than an event was emitted ? #11036

Answered by a-kouyate
a-kouyate asked this question in Q&A
Discussion options

You must be logged in to vote

I found the response. For those who are interested to assert an event is emitted, you can process as follows:

import { medusaIntegrationTestRunner } from "@medusajs/test-utils";
import EventBusService from "@medusajs/test-utils/dist/mock-event-bus-service";
import { asValue } from "awilix";
import { Modules } from "@medusajs/framework/utils";

medusaIntegrationTestRunner({
  moduleName: "example-module",
  testSuite: ({ getContainer }) => {
    let fakeEventBus: jest.Mocked<EventBusService>;

    beforeAll(() => {
      const container = getContainer();

      // Mock EventBusService and spy on the `emit` method
      fakeEventBus = new EventBusService() as jest.Mocked<EventBusService>;

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by a-kouyate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant