未提供“渲染器”的参数

时间:2019-12-06 10:35:03

标签: angular unit-testing jasmine karma-jasmine

这是我的指令:

export class HighlightDirective {

  constructor(private el: ElementRef,
    private renderer: Renderer2) { }

    @HostListener('mouseenter') onMouseEnter() {
      this.renderer.addClass(this.el.nativeElement, 'highlight');
    }

    @HostListener('mouseleave') onMouseLeave() {
      this.renderer.removeClass(this.el.nativeElement, 'highlight');
    }

}

这是对应的规范:

describe('HighlightDirective', () => {
  it('should create an instance', () => {

    let ElementRefMock = {
      nativeElement: document.createElement('div')
    };

    let Renderer2Mock = {
      //CODE
    };

    const directive = new HighlightDirective(ElementRefMock, Renderer2Mock );
    expect(directive).toBeTruthy();
  });
});

请帮助我在spec.ts中模拟Renderer2依赖项

0 个答案:

没有答案