1. 运行下面的测试用例,报错:
Expeced '' to contain 21.
So after set the property(after component.myVote = 1) ,we should cal
l fixture.detectChanges();参考1参考2
报错:Expected 0 to be 3
2.运行下面的测试用例:
it(
'should load todos from the server', ()
=> {
let
service =
TestBed.
get(
TodoService);
spyOn(
service,
'getTodos').
and.
returnValue(
Observable.
from([ [
1,
2,
3] ]));
expect(
component.
todos.
length).
toBe(
3);
});
这是因为fixture.detectChanges();应该改为如下:
it(
'should load todos from the server', ()
=> {
let
service =
TestBed.
get(
TodoService);
spyOn(
service,
'getTodos').
and.
returnValue(
Observable.
from([ [
1,
2,
3] ]));
fixture.
detectChanges();
expect(
component.
todos.
length).
toBe(
3);
});