簡體   English   中英

如何測試 NGXS 選擇器

[英]How to test NGXS selectors

嗨,我在我的應用程序中使用 NGXS state 管理庫,我有如下選擇器,一切正常,但是當我測試我的應用程序時,出現如下錯誤。 PrintItemsState 是延遲加載。 我注意到的問題是我在這里將 PrintItemsState 作為參數傳遞。

@Selector([PrintItemsState])

但我不知道如何解決它。 我會很高興提出任何建議。

在此處輸入圖像描述

打印項目.selectors.ts

@Injectable()
export class PrintItemsSelectors { 
...

  @Selector([PrintItemsState])
  static filter(state: PrintItemsStateModel): KeyValue<string, string>[] {
    const filters = state.fabricPage.page.Filter;
    const filterKeys = Object.keys(state.fabricPage.page.Filter);
    const activeFilters = [];
    filterKeys.forEach((key) => {
      if (filters[key]) {
        activeFilters.push({key: [key], value: filters[key]});
      }
    });
    return activeFilters;
  }

...
}

打印項目.module.ts

@NgModule({
  declarations: [
    PrintItemsListComponent,
    FabricTableComponent,
    SummaryTableComponent,
    RollCodeDialogComponent,
    CommentDialogComponent
  ],
  imports: [
    PrintItemsRoutingModule,
    SharedModule,
    NgxsModule.forFeature([PrintItemsState])
  ],
  providers: [
    PrintItemsHttpService
  ]
})
export class PrintItemsModule {
}

不幸的是,我仍然沒有解決我的問題。 我已經在他們的 github 上發布了問題,但沒有答案。 我發現了類似的問題,但我使用的是 NGXS 3.7.2,所以它不應該是一個案例。 臨時解決方案是我將選擇器移到 state class 內。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM