角度测试:无法解析Store的所有参数:(?,?,?)

时间:2017-08-03 11:48:19

标签: angular ngrx ngrx-store

我正在尝试将我的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的所有参数:(?,?,?)。

有什么想法吗?

非常感谢

1 个答案:

答案 0 :(得分:0)

我使用了ngrx并测试了store

以下是我遵循的步骤 -

  1. 已导入StoreModuleStore

    import { StoreModule, Store } from '@ngrx/store';
    
  2. 导入我的缩减器

    import { reducers } from './reducers';
    
  3. 在我的StoreModule

    中添加了TestBed
    TestBed.configureTestingModule({
      imports: [
        StoreModule.forRoot({
          categories: reducers // My reducers
        })
      ],
    
  4. 定义store变量

    let store: Store<CategoryState>;
    
  5. 已初始化store

    beforeEach(() => {
      store = TestBed.get(Store);
    
      spyOn(store, 'dispatch').and.callThrough();
    
      fixture = TestBed.createComponent(CategoryListComponent);
      component = fixture.componentInstance;
      fixture.detectChanges();
    });
    
  6. 之后,您可以在测试用例中使用store