angular - Uncaught TypeError : ace. acequire 不是函数

标签 angular unit-testing jasmine karma-jasmine ace-editor

我已将 ng2-ace-editor 用于其中一个组件,并尝试使用 ng test 命令运行测试用例。但由于某些原因,它抛出了 Uncaught TypeError: ace.acequire is not a function 错误。

这是我的 .spec.ts 文件代码:

import { NewModule } from './new.module';
import {AceEditorModule} from 'ng2-ace-editor';
import 'brace';
import 'brace/mode/json';
import 'brace/ext/language_tools';

describe('NewModule', () => {
  let component: NewModule;
  let fixture: ComponentFixture<Module>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [ MaterialModule, ReactiveFormsModule, FormsModule, HttpModule, 
        HttpClientTestingModule, RouterTestingModule, BrowserAnimationsModule,
        AceEditorModule
      ],
      declarations: [ NewModule ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(NewModule);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});

我不知道如何解决这个问题。在某个地方我知道大括号是依赖项并且需要安装它。我确实安装了支架,但它不起作用。我尝试在 angular.json 的脚本中提供依赖项文件,但它不起作用。

代码如下:

"scripts": [
   "node_modules/ace-builds/src-min/ace.js",
   "node_modules/ace-builds/src-min/ext-language_tools.js",
   "node_modules/ace-builds/src-min/mode-javascript.js",
   "node_modules/ace-builds/src-min/mode-typescript.js",
   "node_modules/ace-builds/src-min/mode-json.js",
   "node_modules/ace-builds/src-min/theme-eclipse.js"
]

因为这个其他规范文件没有运行, karma 抛出下面提到的错误。请建议我需要做什么。

Uncaught TypeError: ace.acequire is not a function
    at language_tools.js:1954
    at Object../node_modules/brace/ext/language_tools.js (language_tools.js:1955)
    at __webpack_require__ (bootstrap:76)

最佳答案

我遇到了同样的问题,并通过在 xx.component .ts 文件而不是 .spec.ts 文件中添加代码来修复它。

import 'brace';

关于angular - Uncaught TypeError : ace. acequire 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56834637/

相关文章:

java - 在 Android 中运行单元测试时, Intent 解析为不同的进程

angular - 如何在循环中发送 http get 方法 Typescript

angular - ngRx 继承的效果类不起作用

c# - 如何对工厂方法进行单元测试?

c++ - Iceberg 类和 Google 单元测试

angularjs - 如何在 Protractor e2e 测试中正确单步执行不同页面上的测试?

angular - 我们应该取消订阅 ngxs Selector 吗?

javascript - ionic 2 : How do you reinstantiate @ViewChild if you dismiss the view?

node.js - 在 Node.js 中模拟模块以进行单元测试

javascript - 单元测试,如何检查 $uibModal 的模板是否存在