微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何从 ngxs 模拟 ActionSuccessful

如何解决如何从 ngxs 模拟 ActionSuccessful

我有一个带有 ngOnInit 的组件,看起来像

  ngOnInit() {
this.integrationsFacadeService.getTemplates();
this.actions$
  .pipe(ofActionSuccessful(GetTemplates))
  .subscribe(() => this.integrationsFacadeService.getTemplateOptions());
this.fields = this.getFields();
}

然后在我的测试模块中

describe('AdminCenterIntegrationAddComponent',() => {
  let component: AdminCenterIntegrationAddComponent;
  beforeEach(() => {
    Testbed.configureTestingModule({
      providers: [AdminCenterIntegrationAddComponent,{ provide: Actions,useValue: createSpyFromClass(Actions) }],}).compileComponents();
    component = Testbed.inject<any>(AdminCenterIntegrationAddComponent);
  });
  it('should be truthy',() => {
    expect(component).toBeTruthy();
  });

  it('ngOnInt should be ok',() => {
    component.ngOnInit();
  });
});

但是“ngOnInt 应该没问题”在这一行失败

this.actions$
  .pipe(ofActionSuccessful(GetTemplates))
  .subscribe(() => this.integrationsFacadeService.getTemplateOptions());

错误

类型错误:无法读取未定义的属性订阅

我试图模拟ActionSuccessful,例如:

        ofActionSuccessful: () => {
          return () => {
            return of([]);
          };
        }

但我仍然遇到同样的错误

感谢任何见解。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。