出于某种原因,这两个规范正在通过,但是第二个规范正在模板内测试插值,使用来自服务的异步数据。为什么不需要用异步包装回调函数?
describe('SaangComponent', () => {
let component: SaangComponent;
let fixture: ComponentFixture<SaangComponent>;
let compiled: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SaangComponent ],
providers: [
{provide: GetSomeService, useValue: getSomeServiceMock}
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SaangComponent);
component = fixture.componentInstance;
compiled = fixture.debugElement.query(By.css('h1')).nativeElement;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should update the h1 attribute with the title', () => {
fixture.detectChanges();
const expectedText = compiled.innerHTML;
expect(expectedText).toEqual('lord');
});
});
const getSomeServiceMock = {
getSomeData() {
return Observable.of({title: 'lord'});
}
};