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.

TypeError: Cannot read property 'default' of undefined

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
maximeduprecommented, Jun 29, 2019

Hey @ptrckhjnl! Did you find a solution? Thanks 😃.

EDIT

Solution here

0reactions
ptrckhjnlcommented, Mar 4, 2019

package.json

{
  "name": "...",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "start:android": "node node_modules/react-native/local-cli/cli.js run-android",
    "start:ios": "node node_modules/react-native/local-cli/cli.js run-ios",
    "test": "jest",
    "tsc": "tsc",
    "style": "prettier --check \"src/**/*.{tsx,ts}\"",
    "lint": "tslint -p tsconfig.json -c tslint.json \"src/**/*.{tsx,ts}\""
  },
  "dependencies": {
    "react": "^16.8.1",
    "react-native": "^0.58.4",
    "react-native-animatable": "^1.3.1",
    "react-native-material-menu": "^0.4.2",
    "react-native-progress": "^3.5.0",
    "react-native-side-menu": "^1.1.3",
    "react-native-vector-icons": "^6.3.0",
    "react-navigation": "^3.3.0"
  },
  "devDependencies": {
    "@babel/core": "^7.2.2",
    "@types/jest": "^24.0.4",
    "@types/react": "^16.8.2",
    "@types/react-native": "^0.57.35",
    "@types/react-native-material-textfield": "^0.12.2",
    "@types/react-navigation": "^3.0.2",
    "@types/react-native-vector-icons": "^4.6.4",
    "@types/react-test-renderer": "^16.8.1",
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": ">=22.0.0 <24.0.0",
    "jest": ">=22.0.0 <24.0.0",
    "metro-react-native-babel-preset": "^0.51.1",
    "prettier": "^1.16.4",
    "react-native-testing-library": "^1.5.0",
    "react-test-renderer": "^16.8.1",
    "ts-jest": "^23.10.5",
    "tslint": "^5.12.1",
    "tslint-config-airbnb": "^5.11.1",
    "tslint-config-prettier": "^1.18.0",
    "tslint-config-standard": "^8.0.1",
    "tslint-react": "^3.6.0",
    "typescript": "^3.3.3"
  }
}

npx envinfo --preset jest

  System:
    OS: Linux 4.20 Manjaro Linux undefined
    CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
  Binaries:
    Node: 11.10.0 - /usr/bin/node
    Yarn: 1.13.0 - /usr/bin/yarn
    npm: 6.8.0 - /usr/bin/npm
  npmPackages:
    jest: >=22.0.0 <24.0.0 => 23.6.0 
Read more comments on GitHub >

github_iconTop 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 >

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