【问题标题】:Routing testing - Location.path() always return empty ""路由测试 - Location.path() 总是返回空“”
【发布时间】:2017-07-17 14:27:28
【问题描述】:

我正在关注this tutorial。这是我发现的唯一一个测试路由的现代示例。随着时间的推移,我想使用模拟组件。可悲的是,the delivered plunker 不起作用。

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

预期的 '' 是 '/home'。

路由器:应用导航到“搜索”将您带到 /search

预期的 '' 是 '/search'。

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

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

你们有什么想法吗?

【问题讨论】:

    标签: angular angular-routing angular2-testing


    【解决方案1】:

    它不能解决问题。但一种解决方法是使用 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')
        );
    
      });
    
    });
    

    【讨论】:

      猜你喜欢
      • 2020-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-27
      • 1970-01-01
      • 2021-04-30
      相关资源
      最近更新 更多