0

Having test code:

it('componentDidUpdate should mount and change props', () => {
    const onChange = jest.fn();
    const wrapper = enzyme
      .mount(
        withTestTheme(
          <JsonInput
            onChange={onChange}
            onValueChange={mockOnValueChange}
            value={exampleJsonStringValidated}
          />),
      );

    expect(wrapper.instance().JsonInputRef).toBeTruthy;
});

I got:

Property 'JsonInputRef' does not exist on type 'Component<{}, {}, any>'.ts(2339)

I want to find the ref (text-area) and then check validity properties in order to write unit test that is why I need it.

render function:

render() {
const { height = '', onValueChange, ...restProps } = this.props;
return (
  <StyledTextArea
    ref={this.JsonInputRef}
    {...restProps}
    onChange={this.handleValueChange}
    height={height}
  />
);
}

Similar question, but does not work: React/JestJS/Enzyme: How to test for reference function?

Tomasz Waszczyk
  • 2,680
  • 5
  • 35
  • 73
  • What does the `render()` function for your JsonInput component look like? Can you please add that to your code example. – Woodrow Oct 23 '19 at 13:32
  • Possible duplicate of [Testing a React component with Enzyme. Typescript can't find instance methods](https://stackoverflow.com/questions/44625581/testing-a-react-component-with-enzyme-typescript-cant-find-instance-methods) – skyboyer Oct 23 '19 at 13:38

0 Answers0