我正在为我的项目编写测试用例。但是不幸的是,在通过输入ng test启动测试之后,我收到了以下错误:
Error: Error in :0:0 caused by: Plotly is
ReferenceError: Plotly is not definedPlotly是一个外部图表库。我试图在test文件中声明它:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MaterialModule } from '@angular/material';
import { WatchlistComponent } from './watchlist.component';
declare let Plotly: any;
describe('SystemComponent', () => {
let component: WatchlistComponent;
let fixture: ComponentFixture<WatchlistComponent>;
let element;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ WatchlistComponent ],
imports: [ FormsModule, MaterialModule ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(WatchlistComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;
fixture.detectChanges();
});
it('should return a positive number', () => {
expect(component.getScreenHeight()).toMatch(/\d+/);
});
});不幸的是,它仍然没有看到Plotly并返回错误。getScreenHeight()函数的第一个测试用例甚至还没有启动。
也许茉莉花在上传之前就已经开始测试了?
编辑:我是通过在文件中包含<script src='plotly.js'></script>来导入Plotly的。Plotly在本地存储在与index.html相同的文件夹中。
发布于 2018-05-18 14:54:24
将plotly.js (带有适当路径)文件加载到Karma测试env中,在karma.config.js中添加文件配置,如下所示:
karma.config.js
config.set({
..
files: ['plotly.js']
..
});https://stackoverflow.com/questions/42205641
复制相似问题