测试后使用业力+ jsamine,我有这样的错误。服务:ContactService应返回可用语言FAILED错误:无法解析ContactService的所有参数:(?)。我不知道导致这种情况的原因。
import {Http} from "@angular/http";
const CONTACT_URL = "./pages/contacts.json"
export class ContactService{
constructor(private http:Http) { }
public getContactById(id: number) {
// return this.get(CONTACT_URL, { id: id });
}
get(){
return this.http.get(CONTACT_URL).map(response => response.json())
}
}
import {inject,TestBed,async} from "@angular/core/testing";
import {ContactService} from "./ContactService.component"
import {HttpModule} from "@angular/http";
describe('Service: ContactService', () => {
let service;
beforeEach(() => TestBed.configureTestingModule({
imports:[HttpModule],
providers: [ ContactService ]
}));
beforeEach(inject([ContactService], s => {
service = s;
}));
it('should return available languages',async(() => {
service.get().subscribe(x=> {
expect(x).toContain('en');
expect(x).toContain('es');
expect(x).toContain('fr');
expect(x.length).toEqual(3);
});
}));
});
以下是我的代码。
改变这个
import {Http} from "@angular/http";
const CONTACT_URL = "./pages/contacts.json"
export class ContactService
至
import {Http} from "@angular/http";
import {Injectable} from '@angular/core';
const CONTACT_URL = "./pages/contacts.json"
@Injectable()
export class ContactService