There is a class with dependencies, I can not understand how to test such things

import scrollTo from './scroll'; import {Renderer2, ElementRef } from '@angular/core'; import { IScrollData } from './scroll-data.interface'; export default class TabsExtension { constructor( private renderer: Renderer2, private el: ElementRef ) {} public configuration; private prevButton; private nextButton; private buttonsWrap; public init(wrap): void { this.generateButtons(); this.appendButtonsToParent(); this.addEventListeners(wrap); this.addTextToButtons(); this.addClassesToElements(); } private generateButtons() { this.prevButton = this.renderer.createElement('button'); this.nextButton = this.renderer.createElement('button'); this.buttonsWrap = this.renderer.createElement('div'); this.renderer.appendChild(this.buttonsWrap, this.prevButton); this.renderer.appendChild(this.buttonsWrap, this.nextButton); } private appendButtonsToParent() { const parent = this.el.nativeElement.parentNode; const refChild = this.el.nativeElement; this.renderer.insertBefore(parent, this.buttonsWrap, refChild); } private scrollElement(to, element) { const scrollData: IScrollData = { element, to, duration: this.configuration.scrollTime || 500, direction: this.configuration.direction }; scrollTo(scrollData); } private addEventListeners(wrapper): void { const scrollWidth = wrapper.nativeElement.scrollWidth; this.renderer.listen(this.prevButton, 'click', () => { this.scrollElement(-scrollWidth, wrapper.nativeElement); }); this.renderer.listen(this.nextButton, 'click', () => { this.scrollElement(scrollWidth, wrapper.nativeElement); }); } private addTextToButtons(): void { const prevText = this.renderer.createText(this.configuration.buttonPrevText || ''); const nextText = this.renderer.createText(this.configuration.buttonNextText || ''); this.renderer.appendChild(this.prevButton, prevText); this.renderer.appendChild(this.nextButton, nextText); } private addClassesToElements(): void { this.renderer.addClass(this.prevButton, this.configuration.buttonPrevClass || ''); this.renderer.addClass(this.nextButton, this.configuration.buttonNextClass || ''); this.renderer.addClass(this.buttonsWrap, this.configuration.buttonsWrapClass || ''); } } 
  • um, what is it all about? What are you trying to test? Why do you manually create elements? - overthesanity
  • From this class I will inherit components. I have such a requirement as a test cover ... This class is one of the module for tabs that can be scrolled. Actually the elements that are created are the buttons when you click on which you can scroll through these tabs. - Gene Bilyy
  • @overthesanity Is there an idea how this can be done, or options to rewrite this class somehow differently? - Gene Bilyy
  • Why do you do it manually if you have Angular? =) - overthesanity
  • there's nothing to cover here, I’ll tell you, there are no test cases, use Angular for such things - overthesanity

0