我有这段代码,但我无法通过测试
/**
* Created by vu.kim.long on 09.02.2017.
*/
import {Component} from '@angular/core';
import {Http, ConnectionBackend, BaseRequestOptions, ResponseOptions, Response} from "@angular/http";
import {MockBackend} from "@angular/http/testing";
import {TestBed, inject, fakeAsync, tick, async} from "@angular/core/testing";
import {GroupFormService} from "./group-form.service";
import {GroupFormModule} from "./group-form.module";
export function main() {
describe('GroupForm Service', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [{
provide: Http,
useFactory: (backend: ConnectionBackend, defaultOptions: BaseRequestOptions) => {
return new Http(backend, defaultOptions);
}, deps: [MockBackend, BaseRequestOptions]
},
GroupFormService,
MockBackend,
BaseRequestOptions
]
});
});
it("get avaible supervisors",
inject([GroupFormService, MockBackend], async((groupFormService: GroupFormService, mockBackend: MockBackend) => {
let response: string;
groupFormService.setURL("supervisors");
mockBackend.connections.subscribe(c => {
expect(c.request.url).toBe("http://34.249.136.226/bm-rest-api/api/static/supervisors");
c.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify(
{
id: 1,
firstname: "Jostein",
lastname: "Guldal",
enterpriseid: "jostein.guldal",
tags: "supervisor"
}
)
}
)));
});
groupFormService.get().subscribe(res => {
expect(res.json()).toEqual(
{
id: 1,
firstname: "Jostein",
lastname: "Guldal",
enterpriseid: "jostein.guldal",
tags: "supervisor"
})
});
})));
});
}
模拟数据有Jostein作为名字,我将它与Jostein进行比较。我为什么得到:
FAILED TESTS:
GroupForm Service
× get avaible supervisors
Chrome 56.0.2924 (Windows 10 0.0.0)
TypeError: done.fail is not a function
at eval (node_modules/@angular/core/bundles/core-testing.umd.js:53:30)
at eval (node_modules/@angular/core/bundles/core-testing.umd.js:100:21)
我有一个返回主管列表的服务,但是在这个测试中我只是回到主管那里。我做错了吗?