Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to test controllers with FIREBASE_ADMIN_INJECT inject? #5

Open
ziw opened this issue Jun 24, 2021 · 1 comment
Open

How to test controllers with FIREBASE_ADMIN_INJECT inject? #5

ziw opened this issue Jun 24, 2021 · 1 comment

Comments

@ziw
Copy link

ziw commented Jun 24, 2021

hi,
what's the proper way to inject FIREBASE_ADMIN_INJECT in unit tests? I have a controller

@Controller('users')
export class UsersController {
  constructor(
    @Inject(FIREBASE_ADMIN_INJECT) private firebaseAdmin: FirebaseAdminSDK,
  ) {}
}

and in its unit test I'm getting error Nest can't resolve dependencies of the UsersController (?). Please make sure that the argument FIREBASE_ADMIN_INJECT at index [0] is available in the RootTestModule context.

@itsravenous
Copy link

@ziw would love to know if you ever figured this out. I'm writing e2e tests and have tried both overrideProviders:

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

    app = moduleFixture.createNestApplication();

and passing providers:

const MockFirebaseProvider = {
  provide: FIREBASE_ADMIN_INJECT,
  useFactory: async () => {
    return {};
  },
};

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

    app = moduleFixture.createNestApplication();

but in both cases I get a similar error to you:

Nest can't resolve dependencies of the AnimalsService (?). Please make sure that the argument FIREBASE_ADMIN_INJECT at index [0] is available in the AnimalsModule context.

    Potential solutions:
    - If FIREBASE_ADMIN_INJECT is a provider, is it part of the current AnimalsModule?
    - If FIREBASE_ADMIN_INJECT is exported from a separate @Module, is that module imported within AnimalsModule?
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants