../ my-request.component.spec.ts(30,7)中的错误:错误TS2345:类型'{ALL:string;保留:字符串; IN_PROCESS:字串; NEED_INFO:字符串;已完成:字符串; }”不能分配给“ Expected>”类型的参数。
it('#myrequest should call endpoint and return it\'s result', (done) => {
backend.connections.subscribe((connection: MockConnection) => {
expect(connection.request.method).toEqual(RequestMethod.Get);
expect(connection.request.url).toEqual('http://localhost:3000/myrequests');
let options = new ResponseOptions({
body: JSON.stringify({
ALL: "10",
RESERVED: "2",
IN_PROCESS: "2",
NEED_INFO: "2",
COMPLETED: "2"
})
});
connection.mockRespond(new Response(options));
});
service
.getMyRequests()
.subscribe((response) => {
expect(response).toEqual({
"ALL": "10",
"RESERVED": "2",
"IN_PROCESS": "2",
"NEED_INFO": "2",
"COMPLETED": "2"
});
done();
});
service.ts
getMyRequests(): Observable<any> {
return this.http.get(this._url)
.map(response => response.json());
}
来自API的响应
{
"ALL": "10",
"RESERVED": "2",
"IN_PROCESS": "2",
"NEED_INFO": "2",
"COMPLETED": "2"
}