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.

Error while trying to render inside a jest test.

See original GitHub issue

I 'm trying to render BottomSheet inside a test and I’m getting

    Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
    
    Check the render method of `BottomSheetBehavior`.

Any hints?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

5reactions
mitsestcommented, Aug 4, 2020

@Monkeyank thanks for your response.

Now the error is

  console.error node_modules/react-native/Libraries/LogBox/LogBox.js:33
    Warning: `BottomSheetBehavior` uses `getDerivedStateFromProps` but its initial state is undefined. This is not recommended. Instead, define the initial state by assigning an object to `this.state` in the constructor of `BottomSheetBehavior`. This ensures that `getDerivedStateFromProps` arguments have a consistent shape.

  console.error node_modules/react-native/Libraries/LogBox/LogBox.js:33
    Warning: BottomSheetBehavior.getDerivedStateFromProps(): A valid state object (or null) must be returned. You have returned undefined.
3reactions
ankithm28commented, Aug 3, 2020

I had to mock a bunch of things that the Bottom Sheet used. Note that other things you are using that require mocking which are added to the bottom tab content can cause this problem.

jest.mock('reanimated-bottom-sheet');
jest.mock('react-native-reanimated', () => {
  const View = require('react-native').View;
  return {
    Value: jest.fn(),
    event: jest.fn(),
    add: jest.fn(),
    eq: jest.fn(),
    set: jest.fn(),
    cond: jest.fn(),
    interpolate: jest.fn(),
    sub: jest.fn(),
    multiply: jest.fn(),
    sqrt: jest.fn(),
    max: jest.fn(),
    diff: jest.fn(),
    onChange: jest.fn(),
    View: View,
    Extrapolate: { CLAMP: jest.fn() },
    Clock: jest.fn(),
    greaterThan: jest.fn(),
    lessThan: jest.fn(),
    startClock: jest.fn(),
    stopClock: jest.fn(),
    clockRunning: jest.fn(),
    not: jest.fn(),
    or: jest.fn(),
    and: jest.fn(),
    spring: jest.fn(),
    decay: jest.fn(),
    defined: jest.fn(),
    call: jest.fn(),
    block: jest.fn(),
    abs: jest.fn(),
    greaterOrEq: jest.fn(),
    lessOrEq: jest.fn(),
    debug: jest.fn(),
    Transition: {
      Together: 'Together',
      Out: 'Out',
      In: 'In',
    },
  };
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest test does not fail on error while rendering - Stack Overflow
I'm trying to fix some unit test that passes regardless of what happens in the rendering. import React from 'react'; import Component from...
Read more >
Testing if a React component doesn't exist with Jest
Sometimes we want to write tests to check if certain elements are not rendered. For example, we might have a parameter to disable...
Read more >
Troubleshooting - Jest
Tests are Failing and You Don't Know Why​ ... This will run Jest in a Node process that an external debugger can connect...
Read more >
How to make a Jest Test for Error Boundaries
At first glance, the error itself is provided by a callback within the lifecycle of React. componentDidCatch is what will receive the error...
Read more >
Unit Testing in React: Full Guide on Jest and Enzyme Testing
Don't strive for the percentages, avoid writing fake tests, and just try not to lose main component details. Defining the correct order of ......
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