2017-03-09 37 views
3

我用angular-cli來生成我的項目。這是由角CLI生成我的測試和更新,包括路由器,angularmaterial2和angularfire2Angular2 Karma測試失敗:沒有提供令牌FirebaseUrl

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(); 
    })); 
}); 

當我運行它,我得到DI錯誤:失敗:不提供令牌FirebaseUrl! 我該如何解決這個問題?

+0

我也有這個問題。我嘗試了幾種不同的方法無濟於事。我要麼收到錯誤:沒有提供給Token FirebaseUrl的提供者!或錯誤:沒有AngularFire的提供者!或錯誤:沒有提供令牌FirebaseAppName 請參閱我的問題以及:http://stackoverflow.com/questions/42686610/angular-2-error-no-provider-for-token-firebaseappname – busyPixels

回答

4

配置AngularFireModule修復了這個問題。

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(); 

}));

相關問題