Angular6 茉莉花试验中未发现角管

Angular6 茉莉花试验中未发现角管,angular6,karma-jasmine,Angular6,Karma Jasmine,我在使用Jasmine测试我的6个角组件时出错: 找不到管道“paginate”(activityLogDisplay.data的“]项| paginate:config;let index=index)(单击)=”):ng:///DynamicTestModule/ActivitylogComponent。html@59:34 “分页控件”不是已知元素: 我使用的是通过以下命令安装的NgxPaginationModule: npm install ngx-pagination --save

我在使用Jasmine测试我的6个角组件时出错:

找不到管道“paginate”(activityLogDisplay.data的“]项| paginate:config;let index=index)(单击)=”):ng:///DynamicTestModule/ActivitylogComponent。html@59:34 “分页控件”不是已知元素:

我使用的是通过以下命令安装的NgxPaginationModule:

npm install ngx-pagination --save
因此,请注意,我没有使用我自己创建的自定义管道,我使用的是属于我下载的包的管道。我的组件测试在使用管道而不是测试管道本身方面失败。以下是我在html模板中使用分页管道的情况:

 <li class="list-group-item list-group-item-action" 
    *ngFor="let alItem of activityLogDisplay.data | paginate: config; let index = index" 
    (click)="toggleALView(alItem.index)">
我已经将其包含在测试床配置的声明区域中:

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ ActivitylogComponent, NgxPaginationModule ]
    })
    .compileComponents();
  }));
错误消息更改为:

Failed: Unexpected module 'NgxPaginationModule' declared by the module 
'DynamicTestModule'. Please add a @Pipe/@Directive/@Component annotation.
在我的app.module.ts文件中,我在imports数组中列出了NgxPaginationModule,而不是在declarations数组中:

import { NgxPaginationModule } from 'ngx-pagination';

@NgModule({
  declarations: [
    AppComponent,
    ActivitylogComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule,
    NgxPaginationModule,
    RouterModule.forRoot(appRoutes,{useHash:true})
  ],
  providers: [IndexService, AdminIndexService],
  bootstrap: [LandingpageComponent]
})

你知道我需要做什么才能让这个测试正常工作吗?

解决了我的问题。我需要将NgxPaginationModule作为导入添加到我的规范文件中的test bed configureTestingModule区域:

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports : [
        NgxPaginationModule
      ],
      declarations: [ 
        ActivitylogComponent
       ]
    })
    .compileComponents();
  }));

解决了我的问题。我需要将NgxPaginationModule作为导入添加到我的规范文件中的测试床配置测试模块区域:

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports : [
        NgxPaginationModule
      ],
      declarations: [ 
        ActivitylogComponent
       ]
    })
    .compileComponents();
  }));

我的规范中有相同的错误和配置。tsI的规范中有相同的错误和配置
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports : [
        NgxPaginationModule
      ],
      declarations: [ 
        ActivitylogComponent
       ]
    })
    .compileComponents();
  }));