【问题标题】:Angular Unit testing a method that does not have any return statementAngular 单元测试没有任何返回语句的方法
【发布时间】:2020-10-20 09:56:14
【问题描述】:

我的方法:

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

spec.ts:

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
});

谁能帮我写expect语句....

谢谢。!!!

【问题讨论】:

    标签: angular angular-unit-test


    【解决方案1】:

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

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

    【讨论】:

    • 但是这种风格只会在点击前端的按钮时改变......所以除非点击它,否则我不能期望相同的 css。
    • 但是你在测试中调用了component.flyOut()中的方法,所以样式应该会改变。
    猜你喜欢
    • 2020-07-31
    • 2022-01-06
    • 2014-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-26
    • 1970-01-01
    • 2021-06-10
    相关资源
    最近更新 更多