score:2
Accepted answer
what you can do is export your component in addition to the default export. so change it to:
export class mycomponent extends component
in your test, you can now import your actual component instead of the connected component. as you have dispatch
as a prop of your component, you can supply a mock function or a spy (using something like jasmine or sinon) for dispatch
in your test, and you can test if that gets called with the correct parameters.
check out more on redux testing here: http://redux.js.org/docs/recipes/writingtests.html
Source: stackoverflow.com
Related Query
- Unit testing react component that makes ajax calls using JEST
- Unit testing using Jest for React/Redux Component
- Unit testing react redux thunk dispatches with jest and react testing library for "v: 16.13.1",
- Unable to spyon click on button using jest and react testing library for a component testcase
- How to stub async action in componentDidMount for react redux connected component test using Jest
- Testing React Functional Component with Hooks using Jest
- How to mock out sub-components when unit testing a React component with Jest
- Mocha, Enzyme: Unit testing custom functions in react component using enzyme
- Testing an error thrown by a React component using testing-library and jest
- React component using jQuery without require - jest unit tests
- D3js in a React Component Unit Testing using Jest/Enzyme
- Jest testing React component using Electron-Remote in ElectronJS
- Sending props to a React component for a Jest unit test
- Jest Testing Meteor React Component which is using withTracker in Container (meteor/react-meteor-data)
- Unit testing React component using Material UI Dialog
- Mocking simple internal function using Jest for use in rendered React component
- How to use Jest for testing a react component with localStorage?
- How to Unit test the rendering of a child component in the parent component using react testing library?
- Waiting for React component state to update before testing with Jest
- How to mock React Context for testing component with jest
- Error when testing a React Parent that contains a Child React Redux Component using Enzyme Mount
- get state from redux react component in jest unit test
- Is there a way to unit test an innaccessible callback function that is called from a child React component using jest
- Jest Unit test case for React functional component Api call
- React component testing using Jest
- Trying to unit test a React component using Jest and Enzyme
- Create unit test with Jest and React testing library for helper which generate a domain url
- React presentational component unable to read value for <input /> from redux store using react container
- Promise isn't working in react component when testing component using jest
- Problem with testing for error in React component using react-query and axios. Test with React Testing Library, Jest, msw
More Query from same tag
- How can I stop borders blurring when CSS-transform scaling in Chrome?
- Using react hooks to usestate every second and update DOM only if state has changed
- How to access the Redux store outside of a component in React
- Uncaught TypeError: Cannot read properties of undefined (reading 'roll')
- Gatsby navigate returns 404 page
- React this.props.children.apply is not a function
- Fetch is Undefined in Component when Mocking API Error Response with Jest
- Border not aligned properly in PDF [Snippet attached]
- Ref is undefined on useLayoutEffect when using props.children
- Autoresizing on load in AgGrid React
- State of mixin not seen
- How to set same dynamic width of component child for all instances? Web Components
- Set timeout for message with hooks
- Context state being set with useEffect only setting the context to the last useEffect fired
- React app rendering html entities such as ampersand as escaped
- State of Redux is says promise
- In graphql, what is the best way to combine multiple sources where fields in both sources share a common value?
- React async jest not failing as intended
- React: how to add a spinner after click, and change screen after the animation completes
- Catch in redux thunk
- Problem when subfoldering React app + Angular app using Ingress Gateway
- how to execute on click function to show filtered results from search bar in react
- How can I group specific items within an object in the same array and delete them from the core array?
- Add form element on every button click with react
- React import: Navigate one folder up
- ReactJS Test - fsevents is not a function
- How to simulate Material UI's "theme.mixins.toolbar" using SASS
- could not find react-redux context value ; ensure component is wrapped in a <Provider>
- How to use <Trans /> of react-i18next for an alt image translation?
- ChakraUI - Cannot set isIndeterminate = true for CircularProgress as default props in theme extension