I am currently working on testing my Create-User-Component which relies on an Auth Service that includes methods like 'login, logout,' etc.
The Auth Service imports both AngularFireAuth and AngularFirestore, and it is responsible for handling database interactions.
However, I am encountering a null injector error when trying to run my tests, preventing me from progressing further. My goal is to mock out any database interactions to enable isolated component testing.
Despite attempting various strategies such as spying on the auth service, mocking its methods, and simulating the firestore dependency, I have not been successful in resolving this specific error.
In the code snippet below, I attempt to inject a stubbed version of the auth service that should log messages whenever its methods are called, but no logging activities take place.
I would appreciate insights on why this error occurs and how I can effectively mock out my firebase dependencies to facilitate component testing.
Minimalized excerpts from my code:
The component:
import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { AuthService } from 'src/app/core/services/auth.service';
// Component logic here...
The test:
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { AngularFireModule } from '@angular/fire';
import { AngularFirestoreModule } from '@angular/fire/firestore';
import { FormBuilder, FormsModule } from '@angular/forms';
import { AuthService } from 'src/app/core/services/auth.service';
import { CreateUserComponent } from './create-user.component';
// Test setup here...
The service:
import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';
import { AngularFirestore } from '@angular/fire/firestore';
// Service implementation details...
The encountered error:
Chrome 90.0.4430.212 (Windows 10) CreateUserComponent should create FAILED Failed: R3InjectorError(DynamicTestModule)[AuthService -> AngularFireAuth -> InjectionToken angularfire2.app.options -> InjectionToken angularfire2.app.options]: NullInjectorError: No provider for InjectionToken angularfire2.app.options! NullInjectorError: Expected undefined to be truthy. TOTAL: 1 FAILED, 0 SUCCESS