0

我正在尝试将我的 ngrx/Store 声明到规范文件中以测试容器组件。所以我首先导入商店并在 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();
              });
          }));

但我从标题中得到错误,无法解析商店的所有参数:(?,?,?)。

有任何想法吗?

非常感谢

4

1 回答 1

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在测试用例中使用。

于 2017-08-03T11:55:58.127 回答