意想不到的价值' SohoComponentsModule'由模块' DynamicTestModule'

时间:2017-01-19 00:06:50

标签: unit-testing angular typescript karma-jasmine

我正在编写一个有角度的2应用程序并正在使用我们的UI团队库。应用程序的开发很顺利,我可以使用像这样的import语句轻松地使用它们的所有组件。这是我的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>

请帮助!

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

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

1 个答案:

答案 0 :(得分:0)

由于某种原因,角度库导致了这个问题。 我更新了版本,问题已修复。