Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.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
Testing Angular2使用测试中的路由器实例_Testing_Angular_Karma Jasmine_Router - Fatal编程技术网

Testing Angular2使用测试中的路由器实例

Testing Angular2使用测试中的路由器实例,testing,angular,karma-jasmine,router,Testing,Angular,Karma Jasmine,Router,我正在为Angular2组件开发一些Jasmine测试。该组件在构造函数中接收两个参数,一个服务和一个路由器 import {Component , OnInit} from '@angular/core'; import {Router} from '@angular/router-deprecated'; import { HeroService } from './hero.service'; @Component({ ... }) export class HeroesCompo

我正在为Angular2组件开发一些Jasmine测试。该组件在构造函数中接收两个参数,一个服务和一个路由器

import {Component , OnInit} from '@angular/core';
import {Router} from '@angular/router-deprecated';
import { HeroService } from './hero.service';

@Component({
  ...
})

export class HeroesComponent implements OnInit {
  ...
  constructor(
      private heroService: HeroService ,
      private router: Router
  ) { }
  ...
}
我想写一个测试来检查这个组件是否定义得很好,但是我怀疑如何在测试中实例化组件,通过两个参数,第一个(HeroService)很简单,只需使用一个新的,但是,我如何通过第二个参数(Router)?我正在尝试使用一个新的,但我不知道如何传递作为路由构造函数的第一个参数所需的RouterRegistry。有没有其他方法可以做到这一点

import { Router }         from '@angular/router-deprecated';
import { HeroService } from './hero.service';
...
describe('HeroesComponent with new', function () {
  it('should instantiate component', () => {
    expect(new HeroesComponent(new HeroService() , new Router())).toBeDefined('Done!');
  });
});
这会引发以下错误:

app/heroes.component.spec.ts(30,52): error TS2346: Supplied parameters do not match any signature of call target.

提前感谢

嘿,你找到解决办法了吗?我也被困在这个问题上了!嘿,你找到解决办法了吗?我也被困在这个问题上了!