1

我正在使用 ngx-quill 和 image-resize-module 并让它在我的应用程序中工作

import Quill from 'quill';
import ImageResize from 'quill-image-resize-module';
Quill.register('modules/imageResize', ImageResize);

export class MyComponent {

  quillModules = {
    imageResize: {},
    toolbar: [
      ...
    ],
  };
}

在我的 angular.json 中,我在构建和测试的脚本中添加了 quill.js

"scripts": [
  "node_modules/quill/dist/quill.min.js",
]

我的测试文件正在导入 QuillModule

beforeEach(async(() => {
  TestBed.configureTestingModule({
    imports: [
      QuillModule,
      ...
    ],

但是,在我的茉莉花测试中,我收到了这个警告

'quill', '用'覆盖模块/imageResize', 函数 t(e){ ... }

这个错误

{
  "message": "An error was thrown in afterAll\n[object ErrorEvent]",
  "str": "An error was thrown in afterAll\n[object ErrorEvent]"
}

这打破了我的整个测试运行器,它在抛出这个错误之前只运行了大约 40 个测试。我将其缩小到在我的组件中注册 imageResize 模块

Quill.register('modules/imageResize', ImageResize);

如果我删除此行,我的测试将再次运行。

编辑

我找到了修复并添加了答案

4

1 回答 1

0

阅读此github 帖子后,我偶然发现了一个修复程序

我没有导入 Quill,而是导入了 QuillNameSpace,并将 Quill 定义为 QuillNameSpace。

import * as QuillNamespace from 'quill';
import ImageResize from 'quill-image-resize-module';
const Quill: any = QuillNamespace;
Quill.register('modules/imageResize', ImageResize);
于 2019-11-14T17:34:05.620 回答