Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit 6019c28

Browse files
committed
Updating README with jest testing support.
1 parent 1dd7774 commit 6019c28

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,26 @@ imageCacheHoc(Image, {
122122
cachePruneTriggerLimit: 1024 * 1024 * 10
123123

124124
});
125-
````
125+
```
126+
127+
## Jest Test Support
128+
129+
React Native Image Cache HOC must be run in a native environment to work correctly. As a result it will create issues in your jest tests unless you mock it. Since this module is an HOC that adds additional functionality to the standard \<Image\> component, it can be easily mocked with a function that returns the standard \<Image\> component.
130+
131+
**Add the following to your jest mocks:**
132+
133+
```js
134+
jest.mock('react-native-image-cache-hoc', () => {
135+
136+
const mockComponent = require('react-native/jest/mockComponent');
137+
138+
return function() {
139+
return mockComponent('Image');
140+
}
141+
142+
});
143+
```
144+
126145

127146
## Warning
128147

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-image-cache-hoc",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "React Native Higher Order Component that adds advanced caching functionality to the react native Image component.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)