react-native-vector-icons
react-native-vector-icons copied to clipboard
TypeError: Cannot read property 'RNVectorIconsManager' of undefined
- [x] Review the documentation: https://github.com/oblador/react-native-vector-icons
- [x] Search for existing issues (including closed ones): https://github.com/oblador/react-native-vector-icons/issues
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.
Try this
jest.mock('react-native-vector-icons', () => {
return {
RNVectorIconsManager : jest.mock(),
createIconSetFromIcoMoon:jest.fn()
}});
Try this:
jest.mock("react-native", () => ({
NativeModules: {
RNVectorIconsManager: jest.mock()
},
...
Any updates on this?
Upgrading to the newest 9.x version solved this. But it also rendered all previous snapshots invalid. Because now:
- "fontFamily": "Ionicons"
+ "fontFamily": undefined
Was anyone able to resolve this?