Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Unable to run tests when connected to two or more Firebase apps #2555

michaelyfan started this conversation in Ideas
Discussion options

Version info

Angular: 9.0.2

Firebase: 7.8.0

AngularFire: ^6.0.0-rc.1

Other (e.g. Ionic/Cordova, Node, browser, operating system):

  • node: 14.4.0
  • npm 6.14.4
  • macOS 10.15.5

How to reproduce these conditions

Stackblitz example:
https://stackblitz.com/edit/angular-fire-start-nv2mnn

Steps to set up and reproduce

The Stackblitz example has a crude reproduction of my code.

Yes, I'm aware I intentionally left out .initializeApp() in my code. More on that below...

Sample data and security rules

Firebase project with no security rules--this isn't really relevant to my issue

Debug output

When running npm run test, I receive this error in my Karma HTML runner:

NullInjectorError: R3InjectorError(DynamicTestModule)[FirebaseHelperService -> RoutesAngularFirestore -> InjectionToken angularfire2.app.options -> InjectionToken angularfire2.app.options]: 
 NullInjectorError: No provider for InjectionToken angularfire2.app.options!

Screenshot:
image

There are many Google-able resolutions to this problem, all which involve invoking .initializeApp(). I'm aware I intentionally left that out. More on that below...

Expected behavior

My tests run as normal!

Actual behavior

See "Debug output"

Special notes

I'm trying to connect my app to two Firebase projects at once. I've scoured around and there aren't really any official/standardized procedures for this, so I'm using this solution suggested in a comment on an open repo. I tried to recreate it as best as I could in the stackblitz.

The solution works well, but it doesn't require that I invoke initializeApp anywhere. So that thing where you go

imports: [
 AngularFireModule.initializeApp(yourFirebaseConfig),
 AngularFirestoreModule,
 // ... the rest
],

is not something that I have in my project.
I've always been a bit uncomfortable with this, since it doesn't seem like common practice at all, but I don't know how get over it, since doing the above would force me to choose a single Firebase project, which is what I'm trying to avoid all this time. I'm also worried that initializing w.r.t a single Firebase project, and then having providers for two Firebase projects, would cause some sort of unexpected behavior / conflict / headache which is why I haven't bothered.

So, how do I get past this? I'd like to connect to two Firebase projects, but I'd also like my tests to run, and know once and for all if what I'm doing is "the way" or not.

You must be logged in to vote

Replies: 2 comments

Comment options

AngularFireModule expects the options available to DI via the FIREBASE_OPTIONS, which is provided automatically when you call the initializeApp static method. I've been meaning to document how to work with multiple apps better.

You must be logged in to vote
0 replies
Comment options

Hey guy, I have problem too. Can u help me how to fix ? tks

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
Converted from issue

This discussion was converted from issue #2555 on December 10, 2020 02:47.

AltStyle によって変換されたページ (->オリジナル) /