如何在Angular Unittest中模拟StoreModule
我正在尝试测试一个具有以下存储的组件如何在Angular Unittest中模拟StoreModule,angular,unit-testing,karma-jasmine,Angular,Unit Testing,Karma Jasmine,我正在尝试测试一个具有以下存储的组件 this.store.pipe(select('devices')).subscribe((val) => { const deviceList = val.devices.map((d) => { return { ...d, is_online: d.is_online ? 'Active' : 'Inactive', }; });
this.store.pipe(select('devices')).subscribe((val) => {
const deviceList = val.devices.map((d) => {
return {
...d,
is_online: d.is_online ? 'Active' : 'Inactive',
};
});
this.rowData = deviceList;
this.pagination = val.pagination;
this.globalSearch = val.globalSearch;
this.hasFloatingFilter = val.hasFloatingFilter;
this.dropDownList = val.shuffledColumns;
this.selectedItems = val.shuffledColumns.filter((column: Columns) => !column.hide);
this.selectedRows = val.selectedRows;
});
在我的spec文件中,我已经导入了带有Root的StoreModule以及reducer
TestBed.configureTestingModule({
declarations: [
ListComponent,
MockComponent(DataGridComponent),
],
imports: [
RouterTestingModule,
MockModule(SharedModule),
StoreModule.forRoot({devices: devicesReducer}),
ToastrModule.forRoot({
preventDuplicates: true,
closeButton: true,
progressBar: true,
}),
TranslateModule.forRoot({
loader: { provide: TranslateLoader, useClass: JsonTranslationLoader },
}),
],
providers: [
{ provide: DevicesService, useValue: deviceServiceMock },
{ provide: ColumnApi, useClass: MockColumnApi },
],
}).compileComponents();
当第一次运行测试时,它工作正常,但当我重新运行测试时,它显示一个错误,说明状态无法更新
我想知道如何模拟NgRx存储以及模拟选择器,而不是使用实际的减速机检查: