score:0
try to bind your this.submitchoice()
function in the constructor.
this.submitchoice = this.submitchoice.bind(this)
score:0
you are not binding your function to onclick event, you are calling it and since it return nothing you are basically binding undefined to onclick.
this:
onclick={this.submitchoice(this.state.imageurls[0])}
is same as this:
onclick-{undefined}
because
console.log(this.submitchoice(this.state.imageurls[0])) // output will be undefined
so just change your code like this:
onclick={this.submitchoice}
and find another way to pass data, since you are just passing static dammy data it should not be much issue anyway.
score:1
i went for a different test method in the end. this passes:
it('should call the submitchoice method on click', () => {
//arrange
const spy = jest.spyon(app.prototype, 'submitchoice');
const app = shallow(<app />);
//act
const button = app.find('#buttonoption1')
button.simulate('click');
//assert
expect(spy).tobecalled();
})
Source: stackoverflow.com
Related Query
- Mock function not being called in Jest + Enzyme test
- Mocking Axios with Jest in React - mock function not being called
- Enzyme async await mock function not being called
- Jest | Enzyme how to test if function inside a component is being called during onClick event?
- Mock function not being called using jest and testing library on react app
- Mock function is not called in click event while testing with jest and enzyme
- Jest Expected mock function to have been called, but it was not called
- Jest mocked spy function, not being called in test
- Mock function not getting called in jest
- window.history.back() not being called - jest enzyme
- Why does the jest mock function not getting executed in my test with react testing library?
- Mock function not being called with react-testing-library, but original function is called
- React jest enzyme function called test
- Jest mock is not being called when testing a react component
- Jest Mock function is not getting called
- Error: expected mock function to have been called - onclick Jest enzyme
- How can I mock an imported React hook/module and test that it's being called properly on different test cases using Jest
- Mock function not called and not resolving or returning mocked value in React jest API testing
- Jest Enzyme Test Case mock API with Moxios not working
- Jest enzyme mock function not working with toHaveBeenCalled and mock.calls.length
- Jest test fails : TypeError: window.matchMedia is not a function
- Jestjs how to test function being called inside another function
- How to unit test useEffect cleanUp return function using Jest and Enzyme
- Jest -- Mock a function called inside a React Component
- Test if function is called react and enzyme
- How to test default props functions is attached to component or not ? | React | Jest | Enzyme
- In Jest test it says withRouter () is not a function
- Jest enzyme shallow test is not rendering all elements of the React component
- React: Google "One Tap" callback function not being called
- Typescript test with Jest with Enzyme does not recognise components
More Query from same tag
- delete collection firebase in v9
- Passing dynamic argument on onClick inside for does not work
- How to update nested state or values in Typescript and Reactjs?
- How to dynamically change border color in next js with tailwind css?
- Change state with dropdown reactstrap
- React | Call a function outside a component
- React bootstrap custom nav link active style is not working
- Reactjs. Fetch data from server and connect it to i18n
- Expose Loader does not export module globally
- Easy setup react redux with next.js (React)
- Render elements with a wrapper from a map function in react
- Converting React files to Typescript
- What is the best way to calculate the total cart items in the Redux store?
- Using jsPlumb with Webpack React
- REACT, NODE, EXPRESS Error when connect to API
- React server-side and client side rendering not seamless
- Why does adding/removing curly braces in this arrow function cause the text to not display for a ReactJS component?
- Redux with React-Native and mapStateToProps
- Detect Click Anywhere Of DOM Elements with React
- Jest play with Redux actions
- In React, why route can work properly without path
- Material UI Select focus and selected background color
- Why can't my server access my build folder?
- My React + Webpack + Rails + Bootstrap suddently erroring
- Reactjs displays error users.map is not a function
- React.js getting "Cannot find module loadash.template" error
- Pass props and use ID again
- Updating props doesn't invoke componentWillReceiveProps method
- How Webpack bundle in production mode?
- How to pass data from child component to parent component?