有没有人知道如何使用角度2来测试基本的firebase添加项目进行基本单元测试.
我的代码使用的是typescript而不是基本的JavaScript
这就是我正在测试的:
export class AppComponent { ref: Firebase; refUsers: Firebase; refProfiles: Firebase; constructor(){ this.ref = new Firebase("https://markng2.firebaseio.com"); this.refUsers = new Firebase("https://markng2.firebaseio.com/users"); this.refProfiles = new Firebase("https://markng2.firebaseio.com/profiles"); } public addUser(newUser: Object): void{ this.refUsers.push(newUser, ()=>{ }); } }
这是我目前的测试:
import {it, iit, describe, expect, inject, injectAsync, beforeEachProviders, fakeAsync, tick } from 'angular2/testing'; import { AppComponent } from '../app/app'; describe('AppComponent', () => { it('saves an item to Firebase', () => { let refUsers = new Firebase(''); let service = new AppComponent(); spyOn(service.refUsers, 'push'); service.addUser({ item: true }); expect(service.refUsers.push).toHaveBeenCalled(); }) });
这是我在运行测试时遇到的错误: