Get provider injected with key in a NetJS Test

374 views Asked by At

I have a provider which I inject using a key:

export const myProvider = {
    provide: SOME_PROVIDER,
    useFactory: () => {
      return SomeWrappedInstance;
    },
  };

In my tests I want to access this provider which I inject with @Inject(SOME_PROVIDER), how can I do this?

const moduleRef = await Test.createTestingModule({
      imports: [],
      providers: [myProvider]
    }).compile();
1

There are 1 answers

0
Micael Levi On BEST ANSWER

it's easy as doing:

const myProviderValue = moduleRef.get(SOME_PROVIDER)
//    ^? SomeWrappedInstance