我正在尝试在应用程序中测试我们自定义的Jodit编辑器,但即使自动“应创建”测试也失败。失败消息是“未定义Jodit”。
jodit.component.ts
import { Component, OnInit, AfterViewInit, OnDestroy, Input, Output, } from '@angular/core';
declare var Jodit: any;
@Component({
selector: 'app-jodit',
templateUrl: './jodit.component.html',
styleUrls: ['./jodit.component.css']
})
export class JoditComponent implements AfterViewInit, OnDestroy {
@Input() ... ;
@Output() ... ;
ngAfterViewInit() {
this.editor = new Jodit('#' + this.elementId, ...
});
jodit.component.spec.ts
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { JoditComponent } from './jodit.component';
describe('JoditComponent', () => {
let fixture: ComponentFixture<JoditComponent>;
let component: JoditComponent;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ JoditComponent ]
})
fixture = TestBed.createComponent(JoditComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
我真的是Angular的新手,并且进行了测试,但我想知道我是否已声明Jodit变量为false或缺少导入内容。如果有人可以帮助我,我将非常感激。
答案 0 :(得分:1)
在.spec.ts
文件中,您必须import
Jodit并将其捆绑,就像在jodit.component.ts
中一样。也许imports
的{{1}}数组也需要它。
Add a typescript library to angular
检查一下,但在测试中也必须将其导入。
如果我是我,我会使用Angular包装器:https://github.com/jodit/jodit-angular