在构建期间,业力报告
Chrome 55.0.2883 (Windows 7 0.0.0) ERROR
Uncaught ReferenceError: Zone is not defined
问题追溯到" node_modules \ @angular \ core \ testing \ fake_async.js"文件。我使用的是Angular 2.2.1及其Ionic2-RC4项目。
我正在尝试测试HTTP服务。以下是spec文件的内容:
import { TestBed, async, inject } from '@angular/core/testing';
import { BaseRequestOptions, HttpModule, Http, Response, ResponseOptions } from '@angular/http';
import { MockBackend } from '@angular/http/testing';
import { TestService } from './test-service';
describe('Bible Service', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpModule],
providers: [
TestService,
{
provide: Http,
useFactory: (mockBackend, options) => {
return new Http(mockBackend, options);
},
deps: [MockBackend, BaseRequestOptions]
},
MockBackend,
BaseRequestOptions
]
});
});
it('should get a verse', () => {
inject([TestService, MockBackend], (service, mockBackend) => {
expect(service.getTest()).toBe("yes");
});
});
});
如果我不包含beforeEach,karma会正确运行该文件,因此问题与注入代码有关。任何帮助将不胜感激。
这是test-service.ts文件:
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
@Injectable()
export class TestService
{
constructor(private http: Http)
{
}
getTest()
{
return "yes";
}
}