DEV Community

Discussion on: Mocking redux useSelector-hook

 
anshumanburman profile image
anshumanburman

what is "mockAppState"? can you please explain me more?

Thread Thread
 
fredrikbergqvist profile image
Fredrik Bergqvist

mockAppState is the mocked redux state that your component needs to be able to run.
It should include data for all redux nodes that the component is using.

Take a component like this:

//the redux state looks like this;
// {
//   name: "Fredrik",
//   title: "Developer"
// }
import { useSelector } from "react-redux";
const MyComponent = () => {
  const reduxState = useSelector((state) => state)
  return (<h1>Hello {reduxState.name}</h1>)
}
Enter fullscreen mode Exit fullscreen mode

A mocked app state for the above component would look like this:

{
  name: "Mocked name",
 }
Enter fullscreen mode Exit fullscreen mode

So that you can run tests against a state that you have full control over.