It's kinda confusing as I cannot find anything related in docs of Angular 2.0 and Router-deprecated (yes I have to use it still in my project).
My service looks like this:
import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import { AuthHttp , JwtHelper } from 'angular2-jwt';
import { Router } from '@angular/router-deprecated';
import { UMS } from '../common/index';
@Injectable()
export class UserService {
constructor(
private router: Router,
private authHttp: AuthHttp,
private http: Http) {
this.router = router;
this.authHttp = authHttp;
this.http = http;
}
login(v) {
this.http.post(myUrl)
.subscribe(
data => this.loginSuccess(data),
err => this.loginFailure(err)
);
}
}
And my test like this (don't really care about the 'it' part for now):
import { Http } from '@angular/http';
import { AuthHttp, JwtHelper } from 'angular2-jwt';
import { Router } from '@angular/router-deprecated';
import {
beforeEach, beforeEachProviders,
describe, xdescribe,
expect, it, xit,
async, inject
} from '@angular/core/testing';
import { UserService } from './user.service';
describe('User Service', () => {
let service;
beforeEachProviders(() => [
Router,
AuthHttp,
Http,
UserService
]);
beforeEach(inject([UserService], s => {
service = s;
}));
it('Should have a login method',
inject([
Router,
AuthHttp,
Http,
UserService], () => {
expect(service.login()).toBeTruthy();
}));
});
When I run the test I get this error: (btw I'm using angular-cli)
Error: Cannot resolve all parameters for 'Router'(RouteRegistry, Router, ?, Router). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'Router' is decorated with Injectable.
Am I so wrong here?
Aucun commentaire:
Enregistrer un commentaire