如何在Visual Studio Code中使用jasmine-karma编写routerLink测试用例

时间:2017-12-02 08:58:22

标签: angular angular-test angular-testing

我只想测试App.Component.html页面中是否有routeLink='/home'可用。在Udemy的某个地方,我看到了一个关于如何测试routerLink的视频。我遵循了相同的步骤,但我不知道这是Visual Studio Code或角度测试中的其他问题。

注意:请务必阅读代码中的注释

测试如下,

it('AppPage should have a router link named home', async(() => {

    let debugElements = fixture.debugElement.queryAll(By.directive(RouterLinkWithHref))

     /* 
       Here visual studio code doesn't give me intellisense for findIndex method.
       when I write 'x.', it doesn't give me intellisense for properties 
       but I checked in DOM that such properties property exists. What's wrong? 
     */

    let index = debugElements.findIndex(x=>x.properties['href']==='/home');


    expect(index).toBeGreaterThan(-1);
}))

properties属性存在,如此处所示,

enter image description here

但实际上我得到这样的错误,

enter image description here

有什么问题?

0 个答案:

没有答案