我正在尝试将我的ngrx / Store声明到spec文件中以测试容器组件。所以我先导入商店,然后在beforeEach内部执行以下操作:
import {Store} from '@ngrx/store';
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [NotificationsComponent, NotificationsDevicesComponent,
ToArrayPipe, OrderByDate, TimezoneFormatPipe],
providers: [{ provide: Store, useClass: Store }]
})
.compileComponents().then(() => {
fixture = TestBed.createComponent(NotificationsComponent);
component = fixture.componentInstance;
el = fixture.debugElement;
fixture.detectChanges();
});
}));
但我从标题中得到错误无法解析Store的所有参数:(?,?,?)。
有什么想法吗?
非常感谢
答案 0 :(得分:0)
我使用了ngrx
并测试了store
以下是我遵循的步骤 -
已导入StoreModule
和Store
import { StoreModule, Store } from '@ngrx/store';
导入我的缩减器
import { reducers } from './reducers';
在我的StoreModule
TestBed
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({
categories: reducers // My reducers
})
],
定义store
变量
let store: Store<CategoryState>;
已初始化store
beforeEach(() => {
store = TestBed.get(Store);
spyOn(store, 'dispatch').and.callThrough();
fixture = TestBed.createComponent(CategoryListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
之后,您可以在测试用例中使用store
。