2017-07-17 116 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') 
    ); 

    }); 

});