【问题标题】:Unit Testing Angular app with jQWidgets and Karma/Jasmine使用 jQWidgets 和 Karma/Jasmine 对 Angular 应用程序进行单元测试
【发布时间】:2018-06-27 21:23:38
【问题描述】:

如果有人创建了具有 jQWidgets 的 jasmine/karma Angular 测试 - 即使您没有遇到此错误,我也希望查看您的 karma.conf.js 和 .spec 文件,因为我遇到了问题。

我能够很好地为应用程序提供服务——该应用程序只不过是 Angular 提供的启动器——但我对组件的 .spec 单元测试会在 karma 中引发此错误:

Failed: Unexpected value ‘undefined’ declared by the module ‘DynamicTestModule’

在我的规范文件中:

import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { jqxGridComponent } from 'jqwidgets-scripts/jqwidgets-ts/angular_jqxgrid';

describe('AppComponent', () => {
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [jqxGridComponent, AppComponent]
    }).compileComponents();
  }));

  it('app dummy test', () => {
    expect(1).toBe(2);
  });
});

app.component.ts:

import { Component } from '@angular/core';
import { jqxGridComponent } from 'jqwidgets-scripts/jqwidgets-ts/angular_jqxgrid';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor() {}
}

app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';

import { jqxGridComponent } from 'jqwidgets-scripts/jqwidgets-ts/angular_jqxgrid';

@NgModule({
  declarations: [AppComponent, jqxGridComponent],
  imports: [BrowserModule],
  providers: [],
  bootstrap: [AppComponent] 
})
export class AppModule {} 

如果有任何帮助和/或工作 jqWidget 测试的示例,我将不胜感激。

【问题讨论】:

    标签: angular karma-jasmine jqwidget


    【解决方案1】:

    在 tsconfig.spec.json 中,包含 jqwidgets 文件路径:

    "include": [
        "**/*.spec.ts",
        "**/*.d.ts",
        "../node_modules/jqwidgets-scripts/jqwidgets-ts"
      ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-05
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 2020-07-11
      • 1970-01-01
      相关资源
      最近更新 更多