4

I've been trying to unit test every testable piece of code in my projects and I recently found that Firebase has added Authentication as part of their emulation suite. I'm working on an Angular/Nativescript project right now and I'm running my database tests with the Firestore emulator as a part of my testing environment and I love it. Thing is, a bit of finagling is required to get this to work in the first place.

Basically I just configure TestBed with both the required Firebase modules and provide a SETTINGS object which tells AngularFirestoreModule to target the emulator instead of my production database. It looks something like this:

TestBed.configureTestingModule({
    imports:[
        AngularFireModule.initializeApp(environment.firebaseConfig),
        AngularFirestoreModule
    ],
    providers: [
        //this is what I'm unit testing
        { provide: Database, useClass: FirebaseDatabase },
        //this is the object I provide to my testing environment
        { provide: SETTINGS, useValue: { host: 'localhost:8080', ssl: false } }  
    ]
});

So far so good. Problem is when I try to apply that same concept to Authentication. Going through the AngularFireAuth source code it seems like it requires injection for the mostly the same stuff as the AngularFirestore module except SETTINGS. What do I need to provide in TestBed to target the Authentication emulator?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Ajoscram
  • 41
  • 3

0 Answers0