Hi, I recently upgraded the navigation version in my project to react navigation 5. All the unit test were failing. So I upgraded jest-expo to 36.0.1.
Now some of the tests are working but it still fails in files which import from ‘@react-navigation/stack’.
For eg: In a file with import as:
import { HeaderBackButton } from '@react-navigation/stack'
I get this error
● Test suite failed to run
TypeError: Cannot read property 'split' of undefined
at Object.global (../node_modules/@react-navigation/stack/lib/commonjs/views/Stack/CardStack.tsx:41:26)
at Object.<anonymous> (../node_modules/@react-navigation/stack/lib/commonjs/views/Stack/StackView.tsx:11:1)
It seems to work if I comment out the import statement from the main file (but we cant do that in production)
So, tried to ignore the import statement while running the test file by adding below code to config file.
On line 11 of src/views/Stack/StackView.tsx there is an import statement for CardStack.tsx, so that makes sense at least. But then line 41 of CardStack.tsx the second line of this:
type Props = {
mode: StackCardMode;
insets: EdgeInsets;
I don’t understand how that could give the Cannot read property 'split' of undefined error. Also there is no .split() call anywhere in that file.
I’m not quite sure what transformIgnorePatterns is meant to do, but try this pattern instead: