You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import'react-native'importReactfrom'react'importrendererfrom'react-test-renderer'importListComponentfrom'@components/ListComponent'it('renders list of images with CachedImage component',()=>{constimages: [{id: 1,url: 'https://via.placeholder.com/80x80'},{id: 2,url: 'https://via.placeholder.com/80x80'},{id: 3,url: 'https://via.placeholder.com/80x80'},{id: 4,url: 'https://via.placeholder.com/80x80'},],constcomponent=renderer.create(<ListComponentimages={images}/>)expect(component).toMatchSnapshot()})
Resulting Error:
FAIL src/components/ListComponent/__tests__/ListComponent.test.js
● Console
console.error node_modules/react-native/Libraries/Core/ExceptionsManager.js:71
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the fil
e it's defined in.
Check the render method of `CellRenderer`.
in CellRenderer (created by VirtualizedList)
in View (created by View)
in View (created by ScrollViewMock)
in RCTScrollView (created by Unknown)
in Unknown (created by ScrollViewMock)
in ScrollViewMock (created by VirtualizedList)
in VirtualizedList (created by FlatList)
in FlatList (created by ListComponent)
in View (created by View)
in View (created by ListComponent)
in ListComponent
It renders just fine on the device both Android and iOS but fails in a test. Looks like CellRenderer from VirtualizedList is expecting a component at mount time but CachedImage does not return a valid component? The test will pass if native Image component is used instead of CachedImage.
Was finally able to figure out how to test this component.
Adding the following mocks to the either setupJest.js file or the individual tests should allow the react-test-renderer to render the Image component from CachedImage component. You can also specify another mock for the CustomCachedImage component, but this worked for me.
Ran into this issue when trying to test a component that is implementing CachedImage
Example list component:
ListComponent.js
ListComponent.test.js
Resulting Error:
It renders just fine on the device both Android and iOS but fails in a test. Looks like CellRenderer from VirtualizedList is expecting a component at mount time but CachedImage does not return a valid component? The test will pass if native Image component is used instead of CachedImage.
Thoughts?
Stack:
"react-native": "0.44.0",
"react": "16.0.0-alpha.6",
"jest": "^20.0.0",
"react-test-renderer": "^15.6.1",
The text was updated successfully, but these errors were encountered: