首页 > 解决方案 > Angular 单元测试没有任何返回语句的方法

问题描述

我的方法:

flyout() {
    document.getElementById("transition1").style.cssText="transform:translateX(-120%)";
    document.getElementById("transition2").style.cssText="transform:translateY(-120%)";
}

规格:

it('Tesing Void function', function() {
    const fixture = TestBed.createComponent(AppComponent);
    fixture.detectChanges();
    const component = fixture.debugElement.componentInstance;
    component.flyOut();
    // How should I write expect statement
});

谁能帮我写期望语句....

谢谢。!!!

标签: angularangular-unit-test

解决方案


您可以在期望中查询您的元素并检查样式是否已应用。

fixture.detectChanges();
expect(fixture.debugElement.query(By.css('#transition1')).style.transform).toEqual('translateX(-120%)');

推荐阅读