0
创造了角CLI与Angularfire2单元测试的角度,CLI
下面以一个新的角度2项目是默认组件app.component.ts,它有app.component.spec.ts
import { Component } from '@angular/core';
import { AngularFire } from 'angularfire2'; // import angularfire2
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
af: AngularFire;
constructor(af: AngularFire){
this.af=af;
this.firebaseCall();
}
//push data to firebase collection
firebaseCall(){
let post=this.af.database.list('/post');
post.push({a:'test'});
}
}
贯彻单元测试用于上述firebaseCall()在app.component.spec.ts
我已添加/在更新app.component.spec.ts下面线
import { AngularFire } from 'angularfire2';
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent,AngularFire // extra added
],
});
TestBed.compileComponents();
});
我得到以下错误,而纳克测试
预期的值“AngularFire”被模块DynamicTestModule'
查看AngularFire2源代码,看看如何配置TestBed:https://github.com/angular/angularfire2/blob/2.0.0-beta.8/src/angularfire2.spec.ts #L31-L52 – cartant
添加了此行导入:[AngularFireModule.initializeApp(COMMON_CONFIG)] 获取此错误 在jasmine.DEFAULT_TIMEOUT_INTERVAL指定的超时内没有调用异步回调。 – Prithvi