question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'hide' of undefined

See original GitHub issue
 FAIL  src/App.test.js
  ✕ renders correctly (86ms)

  ● renders correctly

    TypeError: Cannot read property 'hide' of undefined

      45 |     // do stuff while splash screen is shown
      46 |     // After having done stuff (such as async tasks) hide the splash screen
    > 47 |     SplashScreen.hide()
      48 |   }
      49 |
      50 |   render() {

      at App.componentDidMount (src/App.js:47:34)
      at commitLifeCycles (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:5461:24)
      at commitAllLifeCycles (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6250:9)
      at Object.invokeGuardedCallback$1 (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2159:10)
      at invokeGuardedCallback (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2106:29)
      at commitAllWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6371:9)
      at workLoop (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6643:13)
      at Object.invokeGuardedCallback$1 (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2159:10)
      at invokeGuardedCallback (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2106:29)
      at performWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6756:7)

  console.error node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2053
    The above error occurred in the <App> component:
        in App

    Consider adding an error boundary to your tree to customize error handling behavior.
    You can learn more about error boundaries at https://fb.me/react-error-boundaries.

  console.warn node_modules/react-native/jest/setup.js:99
    Calling .blur() in the test renderer environment is not supported. Instead, mock out your components that use findNodeHandle with replacements that don't rely on the native environment.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:10

github_iconTop GitHub Comments

39reactions
rowinbotcommented, Feb 3, 2018

Solution is simple, because of the use of Native Modules, when you are running into a test environment those modules are unavailable, so you have to make a jest mock to actually test it, just like this:

jest.mock('react-native-splash-screen', () => {
  return { 
    hide: jest.fn(),
    show: jest.fn()
  };
});
1reaction
ghasemikasra39commented, Sep 4, 2020

Getting this error for react-native-bootsplash, adding mocks did not help

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular: Error 'Cannot read property 'hide' of undefined' when ...
While everything works except closing the modal which gives me error "TypeError: Cannot read property 'hide' of undefined".
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
Uncaught TypeError: Cannot read property of undefined In
Uncaught TypeError: Cannot read property of undefined error occurs in Chrome when you read a property or call a method on an undefined...
Read more >
Uncaught (in promise) TypeError: Cannot read property 'hide ...
Hello! I have just started using Vue.js, so my question may be very simple. I took over a project which I am struggling...
Read more >
How to Avoid the Infamous "Cannot read properties of ... - Bitovi
As a JavaScript developer, I'm sure you've encountered the frustrating runtime TypeError Cannot read properties of undefined .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found