1

I'm trying to develop some Jasmine tests for an Angular2 component. This component receives two parameters in the constructor, a service and a router.

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
  ) { }
  ...
}

I want to write a test to check this component is well defined, but I have doubts about how to instanciate the component in the test passing the two parameters, the first (HeroService) is easy, just using a new , but, ¿how can I pass the second parameter (Router) ? I'm trying to use a new, but I don't know how to pass the RouterRegistry needed as first parameter of Route constructor. Is there another approach to do this?

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

This raises this error:

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

Thanks in advance

rtrujillor
  • 1,162
  • 1
  • 12
  • 23

0 Answers0