B
B
bpGusar2018-10-12 17:42:59
JavaScript
bpGusar, 2018-10-12 17:42:59

How to test a function with another function from Redux inside using Jest?

I started to study tests and stuck at this point
There is a function:

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)
      );
    }
  };

I started writing a test for her
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 } }
    });
  });

And I got an error:
TypeError: _this.props.CountyItemClick is not a function
As I understand it, it swears at the function inside and I don’t understand what to do.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2018-10-12
@miraage

Pass it to props

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question