redux-persist icon indicating copy to clipboard operation
redux-persist copied to clipboard

During Test Redux Persist import Storage fails test

Open HeratPatel1 opened this issue 6 years ago • 6 comments

redux-persist - 5.9.1 react - 16.3.2 jest - 22.4.3

import storage from "redux-persist/es/storage";

({"Object.":function(module,exports,require,__dirname,__filename,global,jest){import createWebStorage from './createWebStorage'; ^^^^^^

SyntaxError: Unexpected token import

  23 |   key: "root",
  24 |   storage,
> 25 |   whitelist: ["provider", "location", "user"]
  26 | };
  27 | 
  28 | const combinedReducer = persistCombineReducers(config, reducers);
  
  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316:17)
  at Object.<anonymous> (app/javascript/bundles/ReduxProvider.jsx:25:16)
  at Object.<anonymous> (app/javascript/bundles/AdminPanel/Location/containers/EditLocationContainer.jsx:13:22)

I also tried with

import storage from "redux-persist/lib/storage";

import React, { PureComponent } from 'react'; // eslint-disable-line import/no-unresolved ^^^^^^

SyntaxError: Unexpected token import

  29 | 
  30 | let AppStore = configureStore(combinedReducer);
> 31 | let persistor = persistStore(AppStore);
  32 | 
  33 | export default class ReduxProvider extends React.Component {
  34 |   render() {
  
  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316:17)
  at Object.<anonymous> (app/javascript/bundles/ReduxProvider.jsx:31:15)
  at Object.<anonymous> (app/javascript/bundles/AdminPanel/Location/containers/EditLocationContainer.jsx:13:22)

console.error node_modules/redux-persist/lib/storage/getStorage.js:40 redux-persist failed to create sync storage. falling back to memory storage.

HeratPatel1 avatar Jun 20 '18 13:06 HeratPatel1

seems like the jest is not compile the library, try to add the config on the jest config file? you can refer jest documents

aaronisme avatar Jun 22 '18 08:06 aaronisme

Same issue here. I'm trying to write tests using ...

"devDependencies": {
    "@types/enzyme": "^3.1.11",
    "@types/enzyme-adapter-react-16": "^1.0.2",
    "@types/faker": "^4.1.2",
    "@types/fetch-mock": "^6.0.3",
    "@types/jest": "^23.1.3",
    "@types/react-test-renderer": "^16.0.1",
    "@types/redux-mock-store": "^1.0.0",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "faker": "^4.1.0",
    "fetch-mock": "^6.4.4",
    "react-scripts-ts": "^2.16.0",
    "react-test-renderer": "^16.4.1",
    "redux-mock-store": "^1.5.3",
    "typescript": "2.9.2"
  }

but I'm getting the below error when import storage from "redux-persist/lib/storage";

$ yarn test
yarn run v1.7.0
$ react-scripts-ts test --env=jsdom
  console.error node_modules\redux-persist\lib\storage\getStorage.js:40
    redux-persist failed to create sync storage. falling back to memory storage.

and same error as @HeratPatel1 's when import storage from "redux-persist/es/storage";

ggsjyoon avatar Jun 29 '18 19:06 ggsjyoon

I'm also running into the same problem. Also tried to switch from import storage from "redux-persist/es/storage" to import storage from "redux-persist/lib/storage" but the error ... persist (no pun intended).

arananegra avatar Aug 23 '19 08:08 arananegra

This is huge disaster from my perspective. redux-persist just shattered my unit test suites. I cannot find any better solution then just to get rid off redux-persist completely. So if you have app with good coverage don't borther installing redux-persist, better write your own custom solution.

bkostrowiecki avatar Oct 17 '21 01:10 bkostrowiecki

I am also facing this issue, any updates on this

Durgesh00 avatar Apr 22 '22 13:04 Durgesh00