路由测试 - Location.path()始终返回空白""

时间:2017-07-17 14:27:28

标签: angular angular-routing angular2-testing

我跟随this tutorial。这是我发现测试路由的唯一现代例子。我想及时使用模拟组件。可悲的是,the delivered plunker不起作用。

  

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

     

预期''成为' / home'。

  

路由器:应用程序导航到"搜索"带你去/搜索

     

预期''成为' /搜索'。

如果我更换,则会出现同样的问题:

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

你们有什么想法吗?

1 个答案:

答案 0 :(得分:0)

它没有解决问题。但是一种解决方法是使用端到端而不是单元测试。

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')
    );

  });

});