Closed danbruegge closed 7 years ago
After a bit of research, looks more like an ios problem. But. I use android and write the code on a linux machine.
You need to mock the native module.
Thanks for the fast answer. But how should i mock it?
Ok, i will have a look. :) Thanks.
@oblador, for me, it's unclear how i should mock the native module. Because i don't know which. Please can you explain it with more details?
I had the same problem and at the end on android it works just mocking the library like that:
jest.mock('react-native-vector-icons/Ionicons', () => ({ ToolbarAndroid: 'ToolbarAndroid' }));
On the other hand, pretty much the same code on ios, with the TabBarItemIOS will complain with: Invariant Violation: There is no registered component for the tag TabBarItemIOS
This is the ios mock:
jest.mock('react-native-vector-icons/Ionicons', () => ({ TabBarItemIOS: 'TabBarItemIOS' }));
Do you know why?
@dbertella awesome, thanks. Looks good now. :)
You're problem looks very common. Maybe you can find help there: https://github.com/facebook/react-native/issues/2066 ?
@danbruegge Actually I found out that it was the TabBarIOS
component that cause the problem, I had to mock it jest.mock('TabBarIOS', () => 'TabBarIOS')
and then the snapshot went through. Still concern about it but it worked.
I was just having this issue and @dbertella suggestion worked for me :
jest.mock('react-native-vector-icons/MaterialIcons', () => { return {TabBarItemIOS:""}})
resolved my problem
Fixed it with:
jest.mock('react-native-vector-icons', () => {
const ActualTabBarIOS = require.requireActual('TabBarIOS');
const React = require('react');
return {
createIconSet: () => {
const Icon = class extends React.Component {
render() {
return jest.fn();
}
}
Icon.TabBarItem = ActualTabBarIOS.Item;
return Icon;
},
createIconSetFromFontello: () => {
return {
TabBarItem: ActualTabBarIOS.Item
}
},
createIconSetFromIcoMoon: jest.fn(),
}
});
Though I am working on TabBarIOS
, but getting the same error
RNVectorIconsManager not available, did you add the library to your project and link with libRNVectorIcons.a?
before the mock.
This code is just enough for my use case. In case if this helps anyone in the future.
I'm a littlebit lost here where do you put the jest.mock part if I place it inside the test file it doesn't seem to have any effect
@ParAnton you need to create a file with the mocks and add it to jest config
"jest": {
...
"setupFiles": [
"./path/to/mocks.js"
]
...
}
Hi, i got an error when i try to run a test with Jest and a wrapped
<Icon.ToolbarAndroid />
.<Toolbar />
Jest test:
The error:
Somone has an Idea and can help?
// Edit
If i remove thenavIconName
the test will pass.