Git Product home page Git Product logo

Comments (9)

andrepav1 avatar andrepav1 commented on May 8, 2024 6

@bratello @zveljkovic had a similar issue, which was fixed by calling await module.init() after building the testing module.

from cqrs.

andynunes avatar andynunes commented on May 8, 2024 1

@DanielMenke Sure thing, however, my use case doesn't override providers. Hope it helps nonetheless:

In beforeAll()

        ...
        this.testingModule = await Test.createTestingModule({
            providers: [
               // only needed providers
            ],
            imports: [
                ConfigurationModule,
                ConfigModule.forRoot({
                    validate: EnvironmentVariables.validate,
                    isGlobal: true
                }),
                EventEmitterModule.forRoot(),
                // other imports
            ]
        }).compile();

        await this.testingModule.init();
        ...

from cqrs.

DanielMenke avatar DanielMenke commented on May 8, 2024 1

@andynunes Thanks!
The problem was that I put EventEmitter2 in the providers AND imported the EventEmitterModule.forRoot(). Only the latter is necessary and gets overridden with an EventEmitter2-instance without any registered listeners as soon as I put the EventEmitter2 inside the providers.

from cqrs.

kamilmysliwiec avatar kamilmysliwiec commented on May 8, 2024

Could you please provide a minimal repository which reproduces your issue?:)

from cqrs.

zveljkovic avatar zveljkovic commented on May 8, 2024

@murbanowicz Did you resolve this issue? I have the same problem, from tests, my event handlers are not triggered...

from cqrs.

bratello avatar bratello commented on May 8, 2024

@murbanowicz Did you resolve this issue? I have the same problem, from tests, my event handlers are not triggered...

Same issue. Did you get some progress? First I decided that some problem happens with async events. I checked with simple sync event - no matter sync or async, they are all seems to be ASSync.

from cqrs.

andynunes avatar andynunes commented on May 8, 2024

@bratello @zveljkovic had a similar issue, which was fixed by calling await module.init() after building the testing module.

Thank you for sharing @andrepav1 - this also fixed a similar issue for me but using the @nestjs/event-emitter package.

from cqrs.

DanielMenke avatar DanielMenke commented on May 8, 2024

@andynunes could you provide a working example? I am also having this problem with the @nestjs/event-emitter package. It is working fine if I create the complete AppModule as TestModule but fails if I only build a subset of its modules.

this works:

const moduleFixture: TestingModule = await Test.createTestingModule({
      imports: [AppModule],
    }).compile();

    app = moduleFixture.createNestApplication();
    await app.init();

this does not:

 const module: TestingModule = await Test.createTestingModule({
      imports: [EventEmitterModule.forRoot()],
      providers: [RecipesService, PrismaService, EventEmitter2],
    })
      .overrideProvider(PrismaService)
      .useValue(mockDeep<PrismaClient>())
      .compile();

    await module.createNestApplication();
    await module.init();

from cqrs.

andynunes avatar andynunes commented on May 8, 2024

@DanielMenke Nice, glad to hear you found the issue!

from cqrs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.