store.js
import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import initState from './initialState.skipCoverage';
import rootReducer from './rootReducer.skipCoverage';
const persistConfig = {
key: 'root',
storage,
version: 0,
};
const persistedReducer = persistReducer(persistConfig, rootReducer);
/* eslint-disable no-underscore-dangle */
const store = createStore(
persistedReducer,
initState,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(),
applyMiddleware(thunkMiddleware)
);
export const persistor = persistStore(store);
export default store;
app.js
import React from 'react';
import { Provider } from 'react-redux';
import store, { persistor } from './state/store.skipCoverage';
import Routes from './Routes';
import './itcss/main.scss';
import Footer from './components/Footer';
import ContactUs from './components/ContactUs';
import CollapsibleList from './components/CollapsibleList';
import collapsibleListContent from './assets/data/collapsibleListSidebar.json';
import prepareForE2e from './helpers/prepareForE2e.skipCoverage';
import { PersistGate } from 'redux-persist/integration/react'; // eslint-disable-line import/first
const app = () => {
prepareForE2e();
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<React.Fragment>
<div className="row">
<div className="col-lg-9 col-md-8 col-sm-12">
<Routes />
</div>
<aside className="col-lg-3 col-md-4 col-sm-12 no-print">
<ContactUs />
<CollapsibleList
content={collapsibleListContent}
panelType="side-panel"
isSecondary
/>
</aside>
</div>
<Footer />
</React.Fragment>
</PersistGate>
</Provider>
);
};
export default app;
app.test.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
错误日志
我正在尝试通过现成的create-react-app测试来测试我的应用负载,并且不会崩溃。我刚刚将redux-persist
v5.10.0添加到我的应用程序中,并设法使其正常运行,但是应用程序测试本身无法正常工作。我还在嘲笑安装程序上模拟本地存储,但是我已经将其删除了,但错误仍然存在。有谁知道为什么测试失败/如何解决?