Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 路由测试-Location.path()始终返回空&引用;_Angular_Angular Routing_Angular2 Testing - Fatal编程技术网

Angular 路由测试-Location.path()始终返回空&引用;

Angular 路由测试-Location.path()始终返回空&引用;,angular,angular-routing,angular2-testing,Angular,Angular Routing,Angular2 Testing,我跟在后面。这是我发现的唯一一个测试路由的现代示例。最后,我想使用模拟组件。可悲的是,它不起作用 路由器:应用程序导航到“”将您重定向到/主页 预期“”为“/home” 及 路由器:应用程序导航到“搜索”将带您进入/搜索 预期“”为“/search” 如果我更换,则会出现相同的问题: imports: [ RouterTestingModule.withRoutes(routes)] //by imports: [ RouterModule.forRoot(routes)] 你们有什么想法吗?

我跟在后面。这是我发现的唯一一个测试路由的现代示例。最后,我想使用模拟组件。可悲的是,它不起作用

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

预期“”为“/home”

路由器:应用程序导航到“搜索”将带您进入/搜索

预期“”为“/search”

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

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

你们有什么想法吗?

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

  });

});

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

  });

});