在测试后使用karma + 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);
});
}));
});

以下是我的代码。
答案 0 :(得分:4)
更改此
import {Http} from "@angular/http";
import {Injectable} from '@angular/core';
const CONTACT_URL = "./pages/contacts.json"
@Injectable()
export class ContactService
要
@Pointcut("call(void org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.onMessage(Message,Channel))")
private void getEventOnMessage(){}