score:4
Accepted answer
i had the same problem
my solution
import * as redux from "react-redux";
jest.mock("react-redux", () => ({
...jest.requireactual("react-redux"),
useselector: jest.fn(),
}));
describe("blabla", () => {
const mockedstate = {
user: {
firstname: "john",
},
};
beforeeach(() => {
redux.useselector.mockimplementation((callback) => {
return callback(mockedstate);
});
});
});
Source: stackoverflow.com
Related Query
- Unable to mock react-redux hooks after migrating to 8
- How to handle side effects when migrating from Redux to React Context API + hooks
- Props received after api hit in Redux loading two times results in React Hooks
- React Hooks And Redux Unable To Edit Form
- How to reload a react component after an update using redux and hooks
- React router redirect after action redux
- How to mock history.push with the new React Router Hooks using Jest
- React Redux dispatch action after another action
- React Router 4.x - PrivateRoute not working after connecting to Redux
- How to get the changed state after an async action, using React functional hooks
- Props not updating when redux state change in React Hooks
- React hooks state variable not updating after rerender
- How to execute store.unsubscribe from useEffect using React hooks and Redux
- how and when to call a react component methods after state change from redux
- How to compare values from react redux state in hooks
- Unable to run React Native Project on simulator after updating to Xcode 12
- ReactDOM.render: Unable to find node on an unmounted component after React upgrade from 16.4.2 to 16.5.2
- Does it hurt performance to use the react redux hooks in a list?
- Dispatching new action after global state changes in react redux
- React hooks useState/setState not working after sorting the array and passing it
- Dispatch Redux action after React Apollo query returns
- Redirect to Home after Login on React Redux Application
- How to use the updated value in redux store immediately after the action is dispatched in react js functional components
- React & Redux - state getting empty after route changed
- react hooks setTimeout after setState
- React Redux with redux-observable use the router to navigate to a different page after async action complete
- How to resolve a promise after react hooks setState complete?
- How to fix unable to resolve module react redux hooks\useDispatch?
- Component does not rerender but redux state has changed via react hooks
- React Redux store state update process after saving to database
More Query from same tag
- Redux action call returns undefined then defined
- Event not firing on a newly created window with Reactjs
- How to send props in class component to functional component?
- Can you use a React state which contains string data in an element?
- React . How to save into a variable ,and not in console.log()
- Toast is not working (react-toastify component)
- Arguments before a colon
- CSSTransitionGroup replacing
- I wonder if I can have a redux store in the library and the App also have a redux store
- How to Use URL Parameters and Query Strings With React Router
- How to call parent function in child component
- React Typesscript consuming component callback
- Trigger onClick event for a ReactJS element
- ...rest not working in Edge, React project
- React router is not reloading page when url matches the same route
- How can I tell my React app which component I want to update in Firestore?
- on submit button click, execute function then submit form react.js
- Are there any drawbacks to passing a state setter to a helper function?
- gulp build failing with cryptic ENOENT
- Using .map() helper with bootstrap <Col sm="4" /> layout in React
- Babel register tutorial is not working
- React context value with typescript, not able to get the useState
- How to use input from user to countdown?
- Verify if a phone number exist in firebase app using firebase cloud function
- React - Populating First Select Option with Redux State
- How do I get onChange to work with several form fields in Reactjs?
- unable to get an array of svg files from public folder to component in React js
- Can't get cookies with js-cookie and react
- Dispatch an action in a connected component
- How to clear the state so that the previous state doesn't render in the current component?