这是我的指令:
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依赖项