Karma 和 Jasmine 测试 - 用单元测试覆盖诸如点击之类的事件

时间:2021-07-15 05:14:40

标签: javascript jasmine karma-jasmine

你能帮忙吗,我面临以下异常,不知道如何处理。

enter image description here

我在sliders.js 中有一个代码

const btnContainer1 = document.querySelector('.arrow-buttons-wrap');
const sliderBody1 = document.querySelector('.latest-portfolio-slider');
const sliderItems1 = document.getElementsByClassName('latest-portfolio__card');
const sliderLine1 = document.querySelector('.latest-portfolio-slider-line');

const sliderBody2 = document.querySelector('.testimony-slider');
const sliderLine2 = document.querySelector('.testimony-slider-line');
const sliderItems2 = document.querySelectorAll('.slider-item');
const btnContainer2 = document.querySelector('.latest-testimonials__content');


export function Slider(btnContainer, sliderBody, sliderItems, sliderLine) {    
    this.INTERVAL = 2000;
    this.count = 0;
    this.width;
    this.id = setInterval( () => { this.next() }, this.INTERVAL );
    
    this.rollSlider = function() {
        sliderLine.style.transform = `translate(-${this.count * this.width}px)`;
    };
    this.prev = function() {
        clearInterval(this.id);
        sliderLine.prepend(sliderItems[sliderItems.length - 1]);
        this.rollSlider();
        this.id = setInterval(  () => { this.prev() }, this.INTERVAL );
    };
    this.next = function() {
        clearInterval(this.id);
        sliderLine.append(sliderItems[0]);
        this.rollSlider();
        this.id = setInterval( () => { this.next() }, this.INTERVAL );
    };
    this.onClick = function(e) {
      let act = e.target.dataset.act;
      if (act) {
        this[act]();
      }
    };
}

有一个规范文件

enter image description here

我不知道如何解决它。如果你只是显示一个方向,那就太棒了!

0 个答案:

没有答案