Quiero probar si se hace clic en el botón y suceden algunas acciones, pero no paso la prueba y recibo 0 cantidad de llamadas cuando se hace clic. No estoy pasando la función onclick de props. Estoy usando el botón materialUi
const LoginFunction = () => { const handleClick = () => { console.log('some action here') }; return ( <Button data-test="btn" className='btn' onClick={() => { handleClick(); }} > Some text </Button> )};Escribí una prueba como esta
describe('Test Login component', () => { it('should trigger click event', () => { const mockCallBack = jest.fn(); const wrapper = shallow(<LoginFunction />); wrapper.simulate('click'); expect(mockCallBack.mock.calls.length).toBe(1); }); });Intenté de esta manera también
describe('Test Login component', () => { it('should trigger click event', () => { const mockCallBack = jest.fn(); const wrapper = shallow(<LoginFunction />); wrapper.find('.btn').simulate('click'); expect(mockCallBack.mock.calls.length).toBe(1); }); });**Also in the main component you can directly call the handler in onclick like this** <Button data-test="btn" className='btn' onClick={handleClick} > Some text </Button> describe('Test Login component', () => { it('should trigger click event', () => { const wrapper=mount( <LoginFunction />); const result=wrapper.find('button').simulate('click') expect(result).toBe('some action here') });