我正在尝试为使用highcharts的组件编写ng2 karma / jasmine测试。我正在使用ng2 RC4和当前的茉莉/业力。
它有一个错误(如下所示,两个测试都有相同的错误)。我看来异步区域中的setInterval是禁止的,但是highcharts在整个地方都使用了setInterval(如下所示,一个例子)&我不确定如何测试这个组件。
有没有人有关于我应该如何编写此测试的链接或信息?
Failed: Cannot use setInterval from within an async zone test.
Error: Cannot use setInterval from within an async zone test.
at AsyncTestZoneSpec.eval [as _failCallback] (/Users//projects/g5-dashboard/dist/vendor/@angular/core/testing/async.js:34:38 <- ../../../../modules/@angular/core/testing/async.ts:37:27)
at AsyncTestZoneSpec.onScheduleTask (/Users//projects/g5-dashboard/dist/vendor/zone.js/dist/async-test.js:93:23)
at ZoneDelegate.scheduleTask (/Users//projects/g5-dashboard/dist/vendor/zone.js/dist/zone.js:333:50)
at Zone.scheduleMacroTask (/Users//projects/g5-dashboard/dist/vendor/zone.js/dist/zone.js:273:40)
at /Users//projects/g5-dashboard/dist/vendor/zone.js/dist/zone.js:1290:26
at setInterval (eval at createNamedFn (/Users//projects/g5-dashboard/dist/vendor/zone.js/dist/zone.js:982:18), <anonymous>:3:38)
at Object.run (/Users//projects/g5-dashboard/dist/vendor/highcharts/highstock.src.js:240:33)
at animate (/Users//projects/g5-dashboard/dist/vendor/highcharts/highstock.src.js:1385:16)
at Object.animate (/Users//projects/g5-dashboard/dist/vendor/highcharts/highstock.src.js:2114:17)
at Object.drawChartBox (/Users//projects/g5-dashboard/dist/vendor/highcharts/highstock.src.js:12985:26)
at Object.redraw (/Users//projects/g5-dashboard/dist/vendor/highcharts/highstock.src.js:12266:23)
at Object.update (/Users//projects/g5-dashboard/dist/vendor/highcharts/highstock.src.js:16464:23)
at Object.setCategories (/Users//projects/g5-dashboard/dist/vendor/highcharts/highstock.src.js:16512:18)
at BarChartComponent.reload_chart (/Users//projects/g5-dashboard/dist/app/shared_components/bar_chart.component.js:111:38
我正在测试组件,如:
describe('InteractionBreakdownComponent', () => {
let fixture: ComponentFixture<any>;
let component: InteractionBreakdownComponent;
beforeEach(() => {
addProviders([
{ provide: Router, useClass: MockRouter },
{ provide: ReportsRouteParamService, useClass: MockParamsService },
{ provide: InteractionBreakdownService, useClass: MockBreakdownReportService }
]);
});
beforeEach(async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(InteractionBreakdownComponent)
.then((fix: ComponentFixture<any>) => {
fixture = fix;
component = fix.componentInstance;
}, err => console.error(err));
})));
it('can be created', () => {
fixture.detectChanges();
expect(component).toBeTruthy();
});
it('sets up params correct', () => {
fixture.detectChanges();
expect(component.start_date).toBe('2015-06');
expect(component.end_date).toBe('2015-09');
});
...