Can';不要让angular2业力测试发挥作用
我有这个代码,但我不能让它通过测试Can';不要让angular2业力测试发挥作用,angular,testing,karma-runner,Angular,Testing,Karma Runner,我有这个代码,但我不能让它通过测试 /** * 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/t
/**
* 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)
我有一个服务返回一个主管列表,但在这个测试中,我只是返回一个主管。我考试做错了吗
我将此作为一个来源: