Search code examples
react-nativejestjsbabeljs

Babel problems with the last version of Jest updating ReactNative


Updating to ReactNative to the last version I'm facing a lot of problems with some test that previously work fine.

at _next (.../node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:9)
    at .../node_modules/@babel/runtime/helpers/asyncToGenerator.js:27:7
    at new Promise (<anonymous>)
...
at _next (.../node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:9)
    at .../node_modules/@babel/runtime/helpers/asyncToGenerator.js:27:7
    at new Promise (<anonymous>)
...
node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:9) {
  cause: undefined
}

It's strange and tough to understand where the problem comes from because there isn't any change in the test that could provoke it so, it must be something that has been changed in jest, babel, or some related dependency.

"jest": "^29.3.1",
"@babel/core": "7.20.12"
"react-native": "0.71.1"

Any idea?


Solution

  • Afterwards, one of my colleagues discovered (thank you Hector :) ) that the problem was how jest deal with promises in the previous versions compared to the last one, just doing the update of ReactNative version by version instead of from the previous to the last one. So, we detected that there was something in the releases that change from 0.70.6 (Nov 15, 2022) to 0.71.0-RC.1 (Nov 23, 2022) that broke our tests.

    It was related to this: polyfilling Promise in Jest.

    And one of the keys was to set the setup file in jest.config.js :

    setupFiles: ['./jest/setup.js'],
    

    with this config:

    global.__DEV__ = true;
    global.Promise = jest.requireActual('promise');
    

    Another thing that was useful for us was taking a look at the jest upgrade guides

    I hope it will help somebody also, for us was a little bit hard to detect the problem. ;)