oblador / react-native-vector-icons

Customizable Icons for React Native with support for image source and full styling.
https://oblador.github.io/react-native-vector-icons/
MIT License
17.42k stars 2.12k forks source link

TypeError: Cannot read property 'RNVectorIconsManager' of undefined #1080

Open ghost opened 5 years ago

ghost commented 5 years ago

OS: Mojave (10.14.6) Target Platform: iOS and Android React-native-vector-icons version: 6.4.2 React-Native: 0.59.9 Jest: 24.8.0

Description

I am trying to run test with jest and I am getting this error:

 FAIL  __tests__/App-test.js
  ● Test suite failed to run

    TypeError: Cannot read property 'RNVectorIconsManager' of undefined

      at Object.RNVectorIconsManager (node_modules/react-native-vector-icons/lib/ensure-native-module-available.js:4:17)
      at Object.<anonymous> (node_modules/react-native-vector-icons/lib/create-icon-set.js:11:1)

My mock for this issues is the following:

jest.mock("NativeModules", () => {
  return {
    RNVectorIconsManager: {
      getImageSource: (fontFamily, glyph, fontSize, color, callback) => {
        return callback(null, require("./app/assets/images/icon.png"));
      },
      getImageForFont: (fontFamily, glyph, fontSize, color, callback) => {
        return callback(null, require("./app/assets/images/icon.png"));
      }
    }
  };
});

Demo

You can use https://snack.expo.io/ to create a demo that can help users to better understand your problem.

ghost commented 4 years ago

Try this

jest.mock('react-native-vector-icons', () => {
  return {
    RNVectorIconsManager : jest.mock(),
    createIconSetFromIcoMoon:jest.fn()
  }});
kimobrian commented 4 years ago

Try this:

jest.mock("react-native", () => ({
  NativeModules: {
    RNVectorIconsManager: jest.mock()
  },
...
MultidimensionalLife commented 3 years ago

Any updates on this?

pke commented 2 years ago

Upgrading to the newest 9.x version solved this. But it also rendered all previous snapshots invalid. Because now:

- "fontFamily": "Ionicons"
+ "fontFamily": undefined
itsfaraaz commented 1 year ago

Was anyone able to resolve this?