A
A
al_542021-08-25 15:29:16
Unit testing
al_54, 2021-08-25 15:29:16

How to test a function that changes state?

const [test, setTest] = useState(5);

  const handleClick = () => {
    setTest(6));
  };
<Button onClick={handleClick}>
            test
 </Button>


сам тест:
test('handleClick', () => {
    const button = rrr.root.findAllByType(Button)[1];
    const mockRenderCustomItem = jest.fn(() => 1);

    expect(button.props.onClick()).toEqual(mockRenderCustomItem);
  });


how to call a function from onClick? now comes just Received: undefined

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question