react-native-safe-area-context icon indicating copy to clipboard operation
react-native-safe-area-context copied to clipboard

Breaks using Jest and RN 0.68.2

Open elliottkember opened this issue 2 years ago • 0 comments

I upgraded this library today:

-    "react-native-safe-area-context": "^3.3.2",
+    "react-native-safe-area-context": "^4.3.1",

and found that Jest is unable to run due to an issue with _NativeSafeAreaContext.default.getConstants. The error reported is below.

 FAIL  __tests__/Initialize.dianastorage.test.tsx
  ● Test suite failed to run

    TypeError: _NativeSafeAreaContext.default.getConstants is not a function

    > 1 | import mockSafeAreaContext from 'react-native-safe-area-context/jest/mock';
        | ^
      2 |
      3 | module.exports = mockSafeAreaContext;
      4 |

      at Object.<anonymous> (node_modules/react-native-safe-area-context/lib/commonjs/InitialWindow.native.js:25:42)
      at Object.<anonymous> (node_modules/react-native-safe-area-context/lib/commonjs/index.tsx:3:1)
      at Object.<anonymous> (node_modules/react-native-safe-area-context/jest/mock.js:20:32)
      at Object.<anonymous> (__mocks__/react-native-safe-area-context.js:1:1)

I logged _NativeSafeAreaContext.default where the error occurs with console.log(_NativeSafeAreaContext);

    { default: {} }

In Jest, _NativeSafeAreaContext.default is {} and not null or void here as the library expects. I don't know whether this is something to do with TurboModules or the new architecture, which I don't have enabled.

elliottkember avatar Jun 12 '22 17:06 elliottkember