TodosComponent类==>
add() {
var newTodo = { title: '... ' };
this.service.add(newTodo).subscribe(
t => {this.todos.push(t); alert();},
err => this.message = err);
}
规范==>
it('should add new to do returned from the server', () => {
let todo={id:1};
let spy = spyOn(service, 'add').and.callFake(t => {
return of([todo]);
});
component.add();
console.log(component.todos); //
expect(component.todos.indexOf(todo)).toBeGreaterThan(-1); //always -1
});