Jest Enzyme test error :Could not find "store" in the context of "Connect(App)"

Ek4m

I have index.js file which contains:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App'
import * as serviceWorker from './serviceWorker';
import {combineReducers,createStore,compose,applyMiddleware} from 'redux'
import {Provider} from 'react-redux'
import thunk from 'redux-thunk'
import { HashRouter } from 'react-router-dom';
import playerReducer from './store/Player/PlayerReducers'
import cardReducer from './store/Cards/cardsReducer'
import playersReducer from './store/Players/PlayersReducer'
import stylesReducer from './store/Styles/StylesReducer'
import gameReducer from './store/Game/gameReducer'
const rootReducer = combineReducers({
    player: playerReducer,
    cards:cardReducer,
    players:playersReducer,
    styles:stylesReducer,
    game:gameReducer
})
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(rootReducer, composeEnhancers(applyMiddleware(thunk)))
ReactDOM.render(
    <Provider store={store}>
     <HashRouter >
      <App />
     </HashRouter>
</Provider>
    , document.getElementById('root'));

serviceWorker.unregister();

export default store

and I have App.js file which contains:

import React, { PureComponent, Suspense } from 'react'
import {connect} from 'react-redux'
import './App.css'
import SignUp from './Register/SignUp'
import SignIn from './Register/SignIn'
import * as stylesActions from './store/Styles/StylesActions'
import Entrance from './components/Entrance/Entrance'
import Profile from './components/Profile/Profile'
import NotFound from './UI/NotFound/NotFound'
import Fallback from './UI/Fallback/Fallback'
import { Route, Switch } from 'react-router-dom'
const Lobby = React.lazy(() => import("./Lobby/Lobby"))
const Game = React.lazy(() => import('./containers/Game/Game'))


class App extends PureComponent {

  render() {
    return (
        <div className="App"
        data-test="App-component"
        >
         <Switch>
         <Route path="/" exact render={() => (
        <Suspense fallback={
      <Fallback />
      }>
          <Entrance />
        </Suspense>
      )} />
    <Route  path="/auth/signup" exact  component={SignUp}/>
      <Route  path="/auth/signin" exact  component={SignIn}/> 
      <Route  path="/lobby" exact render={() => (
        <Suspense fallback={
      <Fallback />
      }>
          <Lobby />
        </Suspense>
      )}/>
      <Route  path="/profile" exact component={Profile}/>
      <Route path="/game" exact render={() => (
        <Suspense fallback={
      <Fallback />
      }>
          <Game />
        </Suspense>
      )} />
      <Route  component={NotFound} />
    </Switch>

        </div>
)
}
}



const mapDispatchToProps = (dispatch) => {
  return {
    onChangeMusicStatus:(arg) => dispatch(stylesActions.musicPaused(arg))

  }
  }
  
  const mapStateToProps = (state) => {
      return {
  player: state.player,
  styles:state.styles,
  players:state.players
      }
  }

  export default connect(mapStateToProps, mapDispatchToProps)(App)

when I try to test it gives me this error

Could not find "store" in the context of "Connect(App)". Either wrap the root component in a or pass a custom React context provider to and the corresponding React context consumer to Connect(App) in connect options.

stasdes

what version of react-redux are you using, can you post your test, if you are using a react-redux 7 you must wrap your text component with Provider:

const TestComponent = <Provider store={store}><App /></Provider>
your test code here...

also you can export only the App component (not the connected) and test it separately.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Jest & Enzyme test error with React Context API

Error shallow Jest Enzyme React cannot find "store"

React error: "could not find the 'store' in the context of ..."

Enzyme test error with redux hooks: "could not find react-redux context value; please ensure the component is wrapped in a <Provider>"

React jest test with enzyme error

Uncaught Error: Could not find "store" in the context of "Connect(RenderPolygons)" in React Redux?

Could not find store in either the context or props of connect site redux error

Could not find "store" in either the context

React / Enzyme: Invariant Violation error when running Jest / Enzyme test

Enzyme/Jest test for useEffect()

Invariant Violation: Could not find "store" in the context of "Connect(AddTodo)".when executing npm test

Could not find "store" in either the context or props

Could not find "store" in the context of "Connect(AppComponent)"

in jest test enzyme.shallow throws Unexpected token < error

Using a Provider but still seeing error Invariant Violation: Could not find "store" in the context of "Connect

Error in react-native with expo: Could not find "store" in the context of "Connect(App)"

"Could not find "store" in the context of" error during the creating of a reusable react-redux package

How to test mapDispatchToProps with Jest & Enzyme?

How to test getDerivedStateFromProps with Jest and Enzyme

Test a form in React with jest and enzyme

Stripe : Could not find Elements context error in nextjs

React-Redux/Jest Invariant Violation: Could not find "store"

enzyme test, context not rendering elements

React, Jest, Enzyme how to pass test App.js with store redux

Jest + Enzyme testing error in mapStateToProps()

How to mock React context in Jest/Enzyme?

Could not find "store" in either the context or props of "Connect(App)"

Invariant Violation: Could not find "store" in either the context or props of "Connect(App)"

React/Redux Testing - Could not find "store" in either the context or props

TOP Ranking

HotTag

Archive