如何使用AngularFirebaseDatabase依赖测试服务?

时间:2019-03-15 14:43:24

标签: unit-testing testing service angular6 angular-testing

这是我的用户。服务

import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import * as firebase from 'firebase';

@Injectable({
  providedIn: 'root'
})
export class UserService {

  constructor(private db: AngularFireDatabase) { }

  save(user: firebase.User) {
    this.db.object('/users/' + user.uid).update({
      name: user.displayName,
      email: user.email,
      photoURL: user.photoURL
    })
  }
}

这是我的user.service.spec.ts

import { TestBed } from '@angular/core/testing';
import { UserService } from './user.service';
import { AngularFireDatabase } from 'angularfire2/database';


describe('UserService', () => {

  beforeEach(() => TestBed.configureTestingModule({
    providers: [
      {provide: AngularFireDatabase}
    ]
  }));

  it('should be created', () => {
    const service: UserService = TestBed.get(UserService);
    expect(service).toBeTruthy();
  });
});

我知道我必须模拟依赖项并侦听是否有returnValue正确吗?

0 个答案:

没有答案