Answer the question
In order to leave comments, you need to log in
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);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question