Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 Karma test failed: No provider for Token FirebaseUrl

I used angular-cli to generate my project. This is my test generated by angular-cli and updated to include router, angularmaterial2 and angularfire2

import { async, TestBed } from '@angular/core/testing';
import { MaterialModule } from '@angular/material';
import { RouterModule } from '@angular/router';
import { AngularFireModule, AuthMethods, AuthProviders } from 'angularfire2';
import { } from 'jasmine';
import { AppComponent } from './app.component';

describe('AppComponent', () => {
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        MaterialModule.forRoot(),
        RouterModule,
        AngularFireModule,
      ],
      declarations: [
        AppComponent,
      ],
      providers: [
      ],
    }).compileComponents();
  }));

  it('should create the app', async(() => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.debugElement.componentInstance;
    expect(app).toBeTruthy();
  }));
});

When I run it I get DI error: Failed: No provider for Token FirebaseUrl! How can I fix this problem?

like image 341
Alexander Zhidkov Avatar asked Mar 25 '26 18:03

Alexander Zhidkov


1 Answers

Configuring AngularFireModule fixed this problem.

  beforeEach(async(() => {
const firebaseConfig = {
  apiKey: 'xxx',
  authDomain: 'xxx',
  databaseURL: 'xxx',
  storageBucket: 'xxx',
  messagingSenderId: 'xxx',
};

TestBed.configureTestingModule({
  imports: [
    MaterialModule.forRoot(),
    RouterModule,
    AngularFireModule.initializeApp(firebaseConfig),
  ],
  declarations: [
    AppComponent,
  ],
  providers: [
  ],
}).compileComponents();

}));

like image 95
Alexander Zhidkov Avatar answered Mar 30 '26 15:03

Alexander Zhidkov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!