react-native-reanimated-bottom-sheet
react-native-reanimated-bottom-sheet copied to clipboard
Error while trying to render inside a jest test.
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?
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?
I'm facing the issue described in the first message. I've tried mocking the components suggested Monkeyank, but still getting the same error. Any ideas on why this happens? :/
I believe the issue that was mentioned with log box can be solved with mocking log box. I believe this happens in rn versions >0.63
Anyone interested mocking LogBox can use the following:
jest.mock('react-native/Libraries/LogBox/LogBox');
Hello! Faced wit the same issue as a topic starter. Jest don't want to render bottom sheet. MB someone has new ideas?