Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用注入服务测试angular2组件_Angular_Angular2 Services_Angular2 Testing - Fatal编程技术网

如何使用注入服务测试angular2组件

如何使用注入服务测试angular2组件,angular,angular2-services,angular2-testing,Angular,Angular2 Services,Angular2 Testing,我查阅了官方文档,但仍然发现一些关于某些元素似乎为空的错误 解决方案是从测试内部的组件实例调用方法 公司名称方法() 请不要将代码添加为截图。如果您希望人们帮助您,那么请花时间帮助他们,提供格式正确、可读的代码,以节省他们重现问题和帮助您解决问题的时间。 //test it('should welcome the user', () => { fixture.detectChanges(); //constcontentel.textContent; expe

我查阅了官方文档,但仍然发现一些关于某些元素似乎为空的错误


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


公司名称方法()

请不要将代码添加为截图。如果您希望人们帮助您,那么请花时间帮助他们,提供格式正确、可读的代码,以节省他们重现问题和帮助您解决问题的时间。
//test

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