score:2
looking at source of gameboard
's handleclick
we can see it does not call this.props.onclick()
.
instead it calls
this.props.updateactiveboardarray(e.target.id)
this.props.changeturn()
so you have to pass those props
in your test and check if they are called:
const e = { target: {id:'x'} }
const updateactiveboardarray = jest.fn();
const changeturn= jest.fn();
let wrapper = shallow(<gameboard
updateactiveboardarray={updateactiveboardarray}
changeturn={changeturn}
/>);
let test = wrapper.find("#gameboard").childat(0).simulate('click', e);
expect(updateactiveboardarray).tohavebeencalledtimes(1);
expect(updateactiveboardarray).tohavebeencalledwith('x');
expect(changeturn).tohavebeencalledtimes(1);
Source: stackoverflow.com
Related Query
- Can't seem to simulate click event with jest
- How to simulate click event with mock function in enzyme and Jest?
- Jest unit test - How do i simulate a click event for table row icon
- Unable to simulate click on Menu Antd with jest and enzyme
- Simulate click event in React with TypeScript material-ui
- Simulate Click Test with Enzyme/ Jest Not Calling Sinon Spy
- How can I simulate click event with enzyme?
- Mock function is not called in click event while testing with jest and enzyme
- Jest on Reactjs for simulate a click with a reference function
- Jest Test of Material-UI Component to Simulate Button click event to fire a Redux Action function
- Simulate a button click in Jest
- Simulate click event on react element
- Unit test: simulate the click event of child component in parent using enzyme
- How to add click event with React createElement
- how to remove an item from a list with a click event in ReactJS?
- Jest error - Not implemented: navigation (except hash changes) when click event is triggered on an anchor element
- How to test a click event with enzyme in a React component's dangerouslySetInnerHTML content
- How to test an onChange input event with enzyme and jest
- Simulate vs props - On Change event using Jest and Enzyme
- Simulate change event to enter text into react textarea with vanilla js script
- In jest/enzyme, how do you simulate a click on an element with eventListener bound by [element].addEventListener (not window.addEventListener)?
- Click event with react-apexcharts
- Simulate a custom Event using Jest and Enzyme
- Jest - "testMatch" doesn't seem to be correctly matching with my file
- Testing React click event in Jest fails because the Jquery can't be applied - How can I test it?
- How to propagate event from element with higher z-index to elements under excluding click event?
- jest enzyme simulate('click') with event object and value
- how add click event and get the dom in the iframe with react-frame-component?
- Jest how to wait for mock to be called based on simulate event
- How can I test a click event which changes a useState state with enzyme?
More Query from same tag
- React State Appears but Only first array is accessible
- Filter empty arrays from object of arrays in JS
- React - How to pass HTML tags in props?
- React Enzyme - Test `componentDidMount` Async Call
- ReactJS Warning: Thumbnails.shouldComponentUpdate(): Returned undefined instead of a boolean value. Make sure to return true or false
- What is the correct typescript type for react children?
- Calculate sum of values in Object of arrays
- Property is missing in type '{ [x: string]: string; }'
- Why state doesn't keep all the data in Array state in hook when it updated in foreach?
- React: SetInterval in ComponentDidMount causing error "Warning: Can't perform a React state update on an unmounted component."
- How To Add Props to a Navbar?
- Start script missing error when running npm start in node-js
- Redirect to website after form submit in react
- How to access props in componentDidMount
- How can I configure Selenium to have an extension pre-installed in Chrome?
- Translations for constants files in react
- ReactJS: Returning div or span from map on Indexed Collections like Int32Array and Float32Array returns 0s and NaNs
- Getting an error "TypeError: Cannot read property 'split' of undefined"
- ES6+ / React Native class properties: The first one is undefined
- get undefined in first render and cant get data
- How to check dynamically rendered checkboxes
- I want my Input to be visible in the next line once I click on Submit Button :: React
- Style option not getting applied on html-to-img
- How can I print multiiple text areas when clicking on a button in reactjs
- No routes matched path
- How to use i18n-iso-countries in React?
- npm ERR! missing script: jasmine
- Module not found: Can't resolve 'react-dom'
- React multiple button on page, to know which one clicked
- How to use hooks inside a conditional statement?