给定的元素没有值设置器

时间:2019-11-20 19:47:53

标签: javascript reactjs react-testing-library

我有一个我想对其进行单元测试的react组件。 我不断收到错误消息:“给定元素没有值设置器”

这是我的代码:

/slider.js

...
<Slider
    id = {title+"slider"}
    className = "slider"
    value={typeof value === 'number' ? value : 0}
    onChange={handleSliderChange}
    aria-labelledby="input-slider"
    min = {min} max = {max} step = {step}
    />

/slider.test.js

import React from "react";
import {render, fireEvent, cleanup} from "@testing-library/react"
import InputSlider from '../Components/slider'

afterEach(cleanup);

describe("move slider changes value", () =>{
  let sliderElement;
  const mymin = 0;
  const mymax = 100;
  const myval = 100
  const title = "mytitle"
  beforeEach(() => {
    const {container} = render(
      <InputSlider
        min = {mymin}//maybe??
        max = {mymax}
        val = {myval}
        title = {title}
      />
    );
    sliderElement = container.querySelector(".slider");
  });
  test("value greater than max", () => {
    fireEvent.change(sliderElement,{
      target:{value:101}
    });
    expect(sliderElement.value).toBe(mymax);
  });
});

我认为问题出在fireEvent.change行上。

0 个答案:

没有答案