iddqd
iddqd

Reputation: 1305

Avoiding provider startup in NestJS tests

When i create a new module in NestJS i prefer testing the entire module as a component test. this means that i start the test with -

const module: TestingModule = await Test.createTestingModule({
      imports: [MyAppModule],
    })

I'd like to override providers that MyAppModule (or one of it's imports) defines, however, it seems their startup code still run, even when i explicitly provide it using

const module: TestingModule = await Test.createTestingModule({
      providers: [{provide: ClassWithStartupCode, useValue: {}}] //option 1
      imports: [MyAppModule],
    }).
.overrideProvider(ClassWithStartupCode) //option 2
.useValue({})

is there any way for the provider to be mocked before MyAppModule is being initiated? is there a better pattern to do this?

Upvotes: 0

Views: 22

Answers (0)

Related Questions