【问题标题】:How to test angular2 component with injected service如何使用注入服务测试 angular2 组件
【发布时间】:2017-03-17 08:43:32
【问题描述】:

我遵循了官方文档,但我仍然收到一些关于某些元素似乎为空的错误。

//test

it('should welcome the user', () => {
    fixture.detectChanges();
    //constcontentel.textContent;
    expect(el.textContent).toContain('Welcome', '"Welcome ..."');
    expect(el.textContent).toContain('Test User', 'expected name');
});

【问题讨论】:

  • 请不要将代码添加为屏幕截图。如果您希望人们帮助您,那么请花时间通过提供格式正确且可读的代码来帮助他们,以节省他们重现问题和帮助您的时间。

标签: angular angular2-services angular2-testing


【解决方案1】:

解决方案是从测试内部的组件实例调用方法

comp.NameOfMethod();

【讨论】:

    猜你喜欢
    • 2017-06-18
    • 1970-01-01
    • 2016-10-31
    • 2017-09-17
    • 1970-01-01
    • 2020-12-21
    • 2021-07-23
    • 2018-06-04
    • 1970-01-01
    相关资源
    最近更新 更多