reduxjs / react-redux

Official React bindings for Redux
https://react-redux.js.org
MIT License
23.37k stars 3.37k forks source link

Test fail with provider in react-native #2137

Closed salarmiirzaeie closed 7 months ago

salarmiirzaeie commented 7 months ago

What version of React, ReactDOM/React Native, Redux, and React Redux are you using?

What is the current behavior?

When we was trying test components using jest and redux in react-native, it said "SyntaxError: Cannot use import statemen outside a module" where we used Provider from react-redux in version 9.1.0 but in react-redux version 8.1.3 it was passed in jest

What is the expected behavior?

It should pass in version 9.1.0 like other version like v 8.13

Which browser and OS are affected by this issue?

No response

Did this work in previous versions of React Redux?

markerikson commented 7 months ago

We updated React-Redux's packaging in v9, and it should be using ESM modules by default. Our tests show it should work with Jest. If you have a specific issue, please provide a repo that shows this error happening so we can investigate.

salarmiirzaeie commented 7 months ago

I created a repo : https://github.com/salarmiirzaeie/react-redux-jest/tree/main image

timdorr commented 7 months ago

You don't have babel-jest hooked up correctly. Add this to your jest.config.js:

"transform": {
  "\\.[jt]sx?$": "babel-jest"
},
gavrilikhin-d commented 2 months ago

You don't have babel-jest hooked up correctly. Add this to your jest.config.js:

"transform": {
  "\\.[jt]sx?$": "babel-jest"
},

I have the same problem. Adding this to config doesn't help

gavrilikhin-d commented 2 months ago

This has helped https://github.com/reduxjs/react-redux/issues/2103#issuecomment-1870389783