TypeError: Cannot read property 'default' of undefined
See original GitHub issueI am not sure if this is a problem of react-native-testing-library
or react-native-vector-icons
.
Versions
"react": "^16.8.1",
"react-native": "^0.58.4",
"react-native-testing-library": "^1.5.0",
"react-test-renderer": "^16.8.1"
Description
TypeError: Cannot read property 'default' of undefined
at new Icon (node_modules/react-native-vector-icons/lib/create-icon-set.js:30:104)
at constructClassInstance (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:3422:22)
at updateClassComponent (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6592:9)
at beginWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7549:20)
at performUnitOfWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11218:16)
at workLoop (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11250:28)
at renderRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11333:11)
at performWorkOnRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12221:11)
at performWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12133:11)
at performSyncWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12107:7)
Reproducible Demo
The test where the error happens:
MenuItems/test.tsx
describe("Prop: onPress", () => {
const onPressMock = jest.fn();
it("calls the passed callback when the menuItems(TouchableOpacity) was pressed", () => {
const { getByTestId } = render(
<MenuItems
{...testProps}
setModalVisible={onPressMock}
setView={onPressMock}
/>
);
fireEvent.press(getByTestId("123"));
expect(onPressMock).toHaveBeenCalledTimes(1);
});
});
MenuItems/index.tsx
export default class MenuItems extends Component<IProps> {
public render() {
return (
<View style={styles.containerWrapper}>
{this.props.icons.map(item => (
<TouchableOpacity
onPress={() => {
this.props.setModalVisible();
this.props.setView(item.id);
}}
key={item.id}
style={styles.container}
>
<Icon name={item.icon} size={30} style={styles.icon} />
<Text style={styles.text}>{item.name}</Text>
</TouchableOpacity>
))}
</View>
);
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
TypeError: Cannot read property 'default' of undefined when i ...
I have issue with tests when i use my custom SideMenu component as contentComponent in createDrawerNavigator: TypeError: Cannot read property ...
Read more >Cannot read property 'default' of undefined when ... - GitHub
I am facing an issue with react-native-vector-icons running in my tests with Jest . The error: TypeError: Cannot read property 'default' of ......
Read more >Jest: TypeError: Cannot read property 'default' of undefined
Even though the project builds just fine in both development and production mode. This usually stems from cyclic dependencies.
Read more >typeerror: cannot read properties of undefined (reading 'default')
Firstly, the error means that whatever you're using .name on has a value of undefined. Typically this can happen if you're making an...
Read more >Use ES6 Arrow Functions to Resolve "TypeError - Pluralsight
1TypeError: Cannot read property '<your property name>' of undefined. If you run into this error while writing React, the odds are high that ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @ptrckhjnl! Did you find a solution? Thanks 😃.
EDIT
Solution here
package.json
npx envinfo --preset jest