@bpGusar
*spoiler*

Как протестировать функцию с другой функцией из Redux внутри с помощью Jest?

Я начал изучать тесты и застрял на этом моменте

Есть функция:

private handleCountyItemClick = (
    e: React.FormEvent<HTMLButtonElement>
  ): void => {
    const { countries } = this.props.countriesRed;
    const selectedId: number = parseFloat(e.currentTarget.dataset.value);
    const foundCountry = countries.find(
      (country: Country, i: number) => i === selectedId
    );
    if (foundCountry) {
      this.props.CountyItemClick(foundCountry);
      this.props.clearInput();
      this.setState({
        dropdownOpen: false,
        fullWidthFullHeightElHeight: 54
      });
      this.countriesListItems.current.style.height = "";
      scrollIt(this.props.countriesRootEl.current, 300, "easeOutQuad", () =>
        enableBodyScroll(this.countriesListItems.current)
      );
    }
  };


я начал писать тест для нее

it("should update the count by 1 when invoked by default", () => {
    const wrapper = shallow(component);
    const instance = wrapper.instance();
    instance.handleCountyItemClick({
      currentTarget: { dataset: { value: 1 } }
    });
  });


И получил ошибку:

TypeError: _this.props.CountyItemClick is not a function

Как я понял ругается на функцию внутри и я не пойму что делать.
  • Вопрос задан
  • 50 просмотров
Пригласить эксперта
Ответы на вопрос 1
miraage
@miraage
Старый прогер
Передать её в props
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы