react-native-pdf: TypeError: Cannot read properties of null (reading 'getConstants')

What react-native version are you using? 0.69.3

What react-native-pdf version are you using? 6.6.2

What platform does your issue occur on? (android/ios/both) Both

Describe your issue as precisely as possible :

  1. Steps to reproduce the issue or to explain in which case you get the issue Run a test that imports PDF. Application runs fine, only npm run test fails.
  2. Interesting logs
 FAIL  __tests__/App-test.tsx
  ● Test suite failed to run

    TypeError: Cannot read properties of null (reading 'getConstants')

      4 | import { styles } from '../styles/common';
      5 | import { RootStackParamList } from '../types';
    > 6 | import Pdf from 'react-native-pdf';
        | ^
      7 |
      8 | export default function PdfSite ({ route }: NativeStackScreenProps<RootStackParamList, 'PdfSite'>) {
      9 |   return (

      at Object.getConstants (node_modules/react-native-blob-util/fs.js:14:39)
      at Object.<anonymous> (node_modules/react-native-blob-util/index.js:9:1)
      at Object.<anonymous> (node_modules/react-native-pdf/index.js:21:1)
      at Object.<anonymous> (src/screens/PdfSite.tsx:6:1)
      at Object.<anonymous> (src/App.tsx:11:1)
      at Object.<anonymous> (__tests__/App-test.tsx:6:1)

Show us the code you are using?

it('renders correctly', () => {
    act(() => {
        comp = create(<App />);
    });

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 4
  • Comments: 17

Most upvoted comments

react-native-blob-util depends on react native turbo module, which should be implemented with native code(android/ios). This error may occur even we use only react-native-blob-util like this issue. To resolve this, we may need to overwrite turbo module with jest mock. Simplest way to suppress the error is mocking react-native-pdf itself. This example for jest setup code may work.

jest.mock('react-native-pdf', () => { return () => <></>})