茉莉花测试是否创建了动态组件

时间:2019-04-02 10:31:08

标签: angular karma-jasmine

我正在服务规范中创建动态组件。

createComponent,此方法将根据其类型创建组件。

  createComponent(content, type: any) {
    if (!type) {
      return this.redirectToRootPath();
    }
    this.componentFactory = this.componentFactoryResolver.resolveComponentFactory(type);
    this.componentReference = this.rootViewContainer.createComponent(this.componentFactory);
    this.componentReference.instance.contentOnCreate(content);
  }

下面是我写的规范,

  it('should call createComponent ', () => {
    spyOn(renderEngineService, 'setRootViewContainerRef');
    spyOn(renderEngineService, 'createComponent');
    renderEngineService.createComponent(NO_INLINE_RANGES, 'HeadingComponent');
    expect(renderEngineService.createComponent).toHaveBeenCalled();
  });

问题是,我收到了一条评论

quite a pointless spy if you call the function yourself :P

那么如何重新编写此规范?

请帮助

0 个答案:

没有答案