Angular Ngrx测试:Store.overrideSelector不会覆盖

我确实有以下beforeEach

beforeEach(() => {
    fixture = TestBed.createComponent(ApplyComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
    store = TestBed.get<Store<fromAnnouncement.AnnouncementState>>(Store);
    store.refreshState();
    mockApplicationSelector = store.overrideSelector(selectDraftApplication,testDraftApplication); <-- Try to mock  a selector here.
  });

选择器selectDraftApplication依赖于AnnouncementState的功能选择器,其中有两个实体,其中一个是使用功能选择器进行子选择,以构建我的selectDraftApplication选择器。

在测试中使用此代码时,我的所有测试都崩溃了,因为NgRx似乎仍在某种程度上寻找所有状态,这时我希望模拟能够阻止这种情况。模拟整个ngrx实体存储是没有意义的,因此我只希望选择器完全返回该对象并完成该操作。我在很远的地方用Google搜索,但没有得到任何答案。有什么帮助吗?我运行Angular 8和ngrx 8.5.1(refreshState()函数也不起作用...)

谢谢!

编辑

export const getannouncementState = createFeatureSelector<AnnouncementState>('announcement');

export const getapplicationsState = createSelector(
  getannouncementState,(state: AnnouncementState) => state.applications 
);

export const selectDraftApplication = createSelector(
  getapplicationsState,(state: ApplicationState) => state.draftApplication
);
hellionhe 回答:Angular Ngrx测试:Store.overrideSelector不会覆盖

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3108669.html

大家都在问