Skip to content

Commit f834eb5

Browse files
authored
Improve and document jest mock setup (#651)
1 parent 813afaf commit f834eb5

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

docs/docs/getting-started/installation.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,23 @@ cd package && yarn && cd ..
5353
cd example && yarn && yarn start
5454
```
5555

56-
To run the example project on iOS, you will need to run `pod install`, and on Android, you will also need Android NDK to be installed ([see here](#android)).
56+
To run the example project on iOS, you will need to run `pod install`, and on Android, you will also need Android NDK to be installed ([see here](#android)).
57+
58+
## Testing with Jest
59+
60+
In order to load the mock provided by React Native Skia add following to your jest config:
61+
62+
```json
63+
"setupFiles": ["./node_modules/@shopify/react-native-skia/jestSetup.js"]
64+
```
65+
66+
Example:
67+
68+
```json
69+
"jest": {
70+
"preset": "react-native",
71+
"setupFiles": ["./node_modules/@shopify/react-native-skia/jestSetup.js"]
72+
}
73+
```
74+
75+

package/jestSetup.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* globals jest */
2+
jest.mock("@shopify/react-native-skia", () =>
3+
require("@shopify/react-native-skia/lib/commonjs/mock")
4+
);

package/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"android/src/**",
2222
"libs/android/**",
2323
"index.js",
24+
"jestSetup.js",
2425
"cpp/**/*.{h,cpp}",
2526
"ios",
2627
"libs/ios/libskia.xcframework",

0 commit comments

Comments
 (0)