React-native-reanimated-bottom-sheet: Error while trying to render inside a jest test.

Created on 29 Jul 2020  路  3Comments  路  Source: osdnk/react-native-reanimated-bottom-sheet

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?

Most helpful comment

@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.

All 3 comments

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',
    },
  };
});

@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.

@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.

Hey @mitsest have you solved this issue?

Was this page helpful?
0 / 5 - 0 ratings