【问题标题】:Unexpected value 'SohoComponentsModule' imported by the module 'DynamicTestModule'模块“DynamicTestModule”导入的意外值“SohoComponentsModule”
【发布时间】:2017-06-03 13:15:11
【问题描述】:

我正在编写一个 Angular 2 应用程序,并且正在使用我们的 UI 团队的库。应用程序的开发进展顺利,我可以通过使用这样的导入语句轻松使用它们的所有组件。这是我的 app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { SohoComponentsModule } from '@infor/sohoxi-angular'; // This is the one in question.

import { AppComponent } from './app.component';
import { licenseGeneratorComponent } from './licenseGenerator.component';
import { emergencyLicenseComponent } from './tabs/emergency/emergencyLicense.component';
import { partnerLicenseComponent } from './tabs/partner/partnerLicense.component';
import { standardLicenseComponent } from './tabs/standard/standardLicense.component';

@NgModule({
  declarations: [
    AppComponent,
    licenseGeneratorComponent,
    emergencyLicenseComponent,
    partnerLicenseComponent,
    standardLicenseComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    SohoComponentsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

这是我在这个应用程序中使用的模板之一,soho 的东西来自这个库:

<div class="row">
  <div class="twelve columns">
  <h1>License Generator</h1>
    <div soho-tabs>
      <ul soho-tab-list>
        <li soho-tab><a soho-tab-title tabId='tabs-normal-emergency'>Emergency Licenses</a></li>
        <li soho-tab><a soho-tab-title tabId='tabs-normal-partner'>Partner Licenses</a></li>
        <li soho-tab><a soho-tab-title tabId='tabs-normal-standard'>Standard Licenses</a></li>
      </ul>

      <div soho-tab-panel tabId='tabs-normal-emergency'>
        <emergency-license></emergency-license>
      </div>
      <div soho-tab-panel tabId='tabs-normal-partner'>
        <partner-license></partner-license>
      </div>
      <div soho-tab-panel tabId='tabs-normal-standard'>
        <standard-license></standard-license>
      </div>
    </div>
  </div>
</div>

该应用程序一直运行良好,没有问题。但是当我的单元测试出现问题时。我之前让他们进行了前几个单元测试,但将其搁置了一周左右并添加了更多内容,现在测试无法正常运行。

当我运行我的测试时,我得到了错误

Unexpected value 'SohoComponentsModule' imported by the module 'DynamicTestModule'

我的 app.component.spec 如下所示:

import { TestBed, async } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';
import { licenseGeneratorComponent } from './licenseGenerator.component';
import { emergencyLicenseComponent } from './tabs/emergency/emergencyLicense.component';
import { partnerLicenseComponent } from './tabs/partner/partnerLicense.component';
import { standardLicenseComponent } from './tabs/standard/standardLicense.component';

import { SohoComponentsModule } from '@infor/sohoxi-angular';

describe('AppComponent', () => {
  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [
        AppComponent,
        licenseGeneratorComponent,
        emergencyLicenseComponent,
        partnerLicenseComponent,
        standardLicenseComponent,
      ],
      imports: [
        FormsModule,
        SohoComponentsModule
      ],
    });
  });

  it('should create the app', async(() => {
    let fixture = TestBed.createComponent(AppComponent);
    let app = fixture.debugElement.componentInstance;
    expect(app).toBeTruthy();
  }));

  it(`should have as title 'app works!'`, async(() => {
    let fixture = TestBed.createComponent(AppComponent);
    let app = fixture.debugElement.componentInstance;
    expect(app.title).toEqual('app works!');
  }));
});

我现在正在兜圈子,因为如果我在测试中删除 import 语句,它会抛出这些错误:

Can't bind to 'closeOnSelect' since it isn't a known property of 'select'. ("label required">Versions</label>

请帮忙!

请记住,应用程序仍然可以正常工作,只是单元测试给我带来了问题。我花了一整天的时间四处寻找修复方法,但无法解决这个问题。

如果我需要发布更多文件,请告诉我。 谢谢, 克里斯

【问题讨论】:

    标签: unit-testing angular typescript karma-jasmine


    【解决方案1】:

    由于某种原因,导致此问题的是 angular 库。 我更新了版本,问题已解决。

    【讨论】:

      猜你喜欢
      • 2021-06-19
      • 1970-01-01
      • 2017-05-07
      • 2020-01-06
      • 2018-05-24
      • 2020-11-23
      • 1970-01-01
      • 2017-12-11
      • 2022-10-13
      相关资源
      最近更新 更多