2017-07-17 112 views
0

我跟随this tutorial。这是我发现测试路由的唯一现代示例。我希望能够使用模拟组件。可悲的是,the delivered plunker不起作用。路由测试 - Location.path()总是返回空“”

路由器:应用程序导航到 “” 您重定向到/ home

预计'是 '/家'。

路由器:应用程序导航到 “搜索” 把你带到/搜索

预计'是 '/搜索'。

有同样的问题,如果我更换:

imports: [ RouterTestingModule.withRoutes(routes)] //by 
imports: [ RouterModule.forRoot(routes)] 

你们是否有一些想法?

回答

0

它不能解决问题。但是一个解决方法是使用E2E而不是单元测试。

describe('navigation',() => { 

    it('root path should redirect to /app',() => { 

    browser.get('http://localhost:49152'); 
    browser.getCurrentUrl().then((url) => 
     expect(url).toBe('http://localhost:49152/app') 
    ); 

    }); 

});