@tarojs/taro-rn 4.0.0-beta.78 → 4.0.0-beta.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/LICENSE +8 -1
  2. package/apiList.js +31 -31
  3. package/dist/api/index.js +1 -1
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/lib/Mask.js +2 -2
  6. package/dist/lib/Mask.js.map +1 -1
  7. package/dist/lib/Popup.js +3 -3
  8. package/dist/lib/Popup.js.map +1 -1
  9. package/dist/lib/StyleSheet.js +1 -1
  10. package/dist/lib/StyleSheet.js.map +1 -1
  11. package/dist/lib/accelerometer.js +1 -1
  12. package/dist/lib/accelerometer.js.map +1 -1
  13. package/dist/lib/chooseMedia/index.js.map +1 -1
  14. package/dist/lib/clearStorage/index.js +2 -2
  15. package/dist/lib/clearStorage/index.js.map +1 -1
  16. package/dist/lib/compressImage/index.js +1 -1
  17. package/dist/lib/compressImage/index.js.map +1 -1
  18. package/dist/lib/connectSocket/index.js.map +1 -1
  19. package/dist/lib/connectSocket/socketTask.js +1 -1
  20. package/dist/lib/connectSocket/socketTask.js.map +1 -1
  21. package/dist/lib/createCameraContext/index.js +3 -3
  22. package/dist/lib/createCameraContext/index.js.map +1 -1
  23. package/dist/lib/createInnerAudioContext/index.js +2 -2
  24. package/dist/lib/createInnerAudioContext/index.js.map +1 -1
  25. package/dist/lib/createVideoContext/index.js +7 -7
  26. package/dist/lib/createVideoContext/index.js.map +1 -1
  27. package/dist/lib/deviceMotion.js +2 -2
  28. package/dist/lib/deviceMotion.js.map +1 -1
  29. package/dist/lib/file.js +4 -4
  30. package/dist/lib/file.js.map +1 -1
  31. package/dist/lib/getAppBaseInfo/index.js +2 -2
  32. package/dist/lib/getAppBaseInfo/index.js.map +1 -1
  33. package/dist/lib/getClipboardData/index.js.map +1 -1
  34. package/dist/lib/getImageInfo/index.js +2 -2
  35. package/dist/lib/getImageInfo/index.js.map +1 -1
  36. package/dist/lib/getLocation/index.js +2 -2
  37. package/dist/lib/getLocation/index.js.map +1 -1
  38. package/dist/lib/getRecorderManager/index.js +5 -5
  39. package/dist/lib/getRecorderManager/index.js.map +1 -1
  40. package/dist/lib/getStorage/index.js.map +1 -1
  41. package/dist/lib/getStorageInfo/index.js +2 -2
  42. package/dist/lib/getStorageInfo/index.js.map +1 -1
  43. package/dist/lib/getSystemInfo/index.js +1 -1
  44. package/dist/lib/getSystemInfo/index.js.map +1 -1
  45. package/dist/lib/getSystemInfoSync/index.js +2 -2
  46. package/dist/lib/getSystemInfoSync/index.js.map +1 -1
  47. package/dist/lib/gyroscope.js +1 -1
  48. package/dist/lib/gyroscope.js.map +1 -1
  49. package/dist/lib/keyboard.js +3 -3
  50. package/dist/lib/keyboard.js.map +1 -1
  51. package/dist/lib/location.js.map +1 -1
  52. package/dist/lib/makePhoneCall/index.js +1 -1
  53. package/dist/lib/makePhoneCall/index.js.map +1 -1
  54. package/dist/lib/media.js +13 -15
  55. package/dist/lib/media.js.map +1 -1
  56. package/dist/lib/network.js +1 -1
  57. package/dist/lib/network.js.map +1 -1
  58. package/dist/lib/offWindowResize/index.js.map +1 -1
  59. package/dist/lib/onWindowResize/index.js +1 -1
  60. package/dist/lib/onWindowResize/index.js.map +1 -1
  61. package/dist/lib/openUrl/index.js +1 -1
  62. package/dist/lib/openUrl/index.js.map +1 -1
  63. package/dist/lib/permission.js +5 -6
  64. package/dist/lib/permission.js.map +1 -1
  65. package/dist/lib/previewImage/index.js +3 -3
  66. package/dist/lib/previewImage/index.js.map +1 -1
  67. package/dist/lib/request/index.js +1 -1
  68. package/dist/lib/request/index.js.map +1 -1
  69. package/dist/lib/scanCode/index.js +22 -22
  70. package/dist/lib/scanCode/index.js.map +1 -1
  71. package/dist/lib/screen.js +2 -2
  72. package/dist/lib/screen.js.map +1 -1
  73. package/dist/lib/setClipboardData/index.js +2 -2
  74. package/dist/lib/setClipboardData/index.js.map +1 -1
  75. package/dist/lib/setKeepScreenOn/index.js +1 -1
  76. package/dist/lib/setKeepScreenOn/index.js.map +1 -1
  77. package/dist/lib/setStorage/index.js.map +1 -1
  78. package/dist/lib/showActionSheet/ActionSheet.js +3 -3
  79. package/dist/lib/showActionSheet/ActionSheet.js.map +1 -1
  80. package/dist/lib/showActionSheet/index.js.map +1 -1
  81. package/dist/lib/showModal/Dialog.js +3 -3
  82. package/dist/lib/showModal/Dialog.js.map +1 -1
  83. package/dist/lib/showModal/index.js.map +1 -1
  84. package/dist/lib/showModal/toast.js +6 -6
  85. package/dist/lib/showModal/toast.js.map +1 -1
  86. package/dist/lib/unsupportedApi.js +4 -2
  87. package/dist/lib/unsupportedApi.js.map +1 -1
  88. package/dist/lib/variable.js +1 -1
  89. package/dist/lib/variable.js.map +1 -1
  90. package/dist/lib/vibrate.js +1 -1
  91. package/dist/lib/vibrate.js.map +1 -1
  92. package/dist/lib/window.js.map +1 -1
  93. package/dist/setup.js +58 -0
  94. package/dist/setup.js.map +1 -0
  95. package/dist/utils/callbackManager.js.map +1 -1
  96. package/dist/utils/index.js.map +1 -1
  97. package/package.json +60 -65
  98. package/src/__tests__/__mock__/mockRNCCameraRoll.js +7 -0
  99. package/src/__tests__/__mock__/mockRNCGeolocation.js +13 -0
  100. package/src/__tests__/__snapshots__/scanCode.test.tsx.snap +154 -0
  101. package/src/__tests__/clipboard.test.ts +88 -0
  102. package/src/__tests__/deviceMotion.test.ts +37 -0
  103. package/src/__tests__/geolocation.test.ts +60 -0
  104. package/src/__tests__/interactive.test.tsx +101 -0
  105. package/src/__tests__/keyboard.test.ts +46 -0
  106. package/src/__tests__/media.test.ts +104 -0
  107. package/src/__tests__/network.test.ts +57 -0
  108. package/src/__tests__/others.test.ts +25 -0
  109. package/src/__tests__/phone.test.ts +31 -0
  110. package/src/__tests__/request.test.ts +146 -0
  111. package/src/__tests__/scanCode.test.tsx +14 -0
  112. package/src/__tests__/storage.test.ts +202 -0
  113. package/src/__tests__/system.test.ts +69 -0
  114. package/src/__tests__/vibrate.test.ts +27 -0
  115. package/src/__tests__/websocket.test.ts +170 -0
  116. package/src/api/index.ts +31 -31
  117. package/src/lib/ENV_TYPE/index.ts +1 -1
  118. package/src/lib/Mask.tsx +2 -2
  119. package/src/lib/Popup.tsx +6 -8
  120. package/src/lib/StyleSheet.ts +1 -1
  121. package/src/lib/accelerometer.ts +1 -2
  122. package/src/lib/arrayBufferToBase64/index.ts +1 -1
  123. package/src/lib/base64ToArrayBuffer/index.ts +1 -1
  124. package/src/lib/chooseMedia/index.ts +1 -1
  125. package/src/lib/clearStorage/index.ts +0 -1
  126. package/src/lib/clearStorageSync/index.ts +1 -1
  127. package/src/lib/compressImage/index.ts +0 -1
  128. package/src/lib/connectSocket/socketTask.ts +9 -7
  129. package/src/lib/createCameraContext/index.ts +4 -6
  130. package/src/lib/createInnerAudioContext/index.ts +0 -1
  131. package/src/lib/createSelectorQuery/index.ts +1 -1
  132. package/src/lib/deviceMotion.ts +3 -4
  133. package/src/lib/file.ts +8 -9
  134. package/src/lib/getClipboardData/index.ts +0 -1
  135. package/src/lib/getEnv/index.ts +1 -1
  136. package/src/lib/getFileSystemManager/index.ts +1 -1
  137. package/src/lib/getLocation/index.ts +3 -4
  138. package/src/lib/getRecorderManager/index.ts +1 -1
  139. package/src/lib/getStorage/index.ts +0 -1
  140. package/src/lib/getStorageInfo/index.ts +0 -1
  141. package/src/lib/getStorageInfoSync/index.ts +1 -1
  142. package/src/lib/getStorageSync/index.ts +1 -1
  143. package/src/lib/getSystemInfo/index.ts +2 -2
  144. package/src/lib/getSystemInfoSync/index.ts +3 -3
  145. package/src/lib/gyroscope.ts +46 -47
  146. package/src/lib/keyboard.ts +4 -5
  147. package/src/lib/location.ts +5 -6
  148. package/src/lib/makePhoneCall/index.ts +1 -2
  149. package/src/lib/media.ts +18 -21
  150. package/src/lib/network.ts +5 -5
  151. package/src/lib/offLocationChange/index.ts +1 -1
  152. package/src/lib/offUserCaptureScreen/index.ts +1 -1
  153. package/src/lib/onLocationChange/index.ts +1 -1
  154. package/src/lib/onUserCaptureScreen/index.ts +1 -1
  155. package/src/lib/onWindowResize/index.ts +2 -2
  156. package/src/lib/openUrl/index.d.ts +22 -23
  157. package/src/lib/openUrl/index.ts +1 -2
  158. package/src/lib/permission.ts +25 -33
  159. package/src/lib/previewImage/index.tsx +3 -4
  160. package/src/lib/removeStorageSync/index.ts +1 -1
  161. package/src/lib/request/index.ts +2 -2
  162. package/src/lib/scanCode/index.tsx +15 -17
  163. package/src/lib/screen.ts +0 -1
  164. package/src/lib/setClipboardData/index.ts +2 -3
  165. package/src/lib/setKeepScreenOn/index.ts +1 -2
  166. package/src/lib/setStorage/index.ts +0 -1
  167. package/src/lib/setStorageSync/index.ts +1 -1
  168. package/src/lib/showActionSheet/ActionSheet.tsx +6 -7
  169. package/src/lib/showActionSheet/index.tsx +0 -1
  170. package/src/lib/showModal/Dialog.tsx +6 -7
  171. package/src/lib/showModal/index.tsx +0 -1
  172. package/src/lib/showModal/toast.tsx +11 -12
  173. package/src/lib/startGyroscope/index.ts +1 -1
  174. package/src/lib/startLocationUpdate/index.ts +1 -1
  175. package/src/lib/unsupportedApi.ts +5 -3
  176. package/src/lib/vibrate.ts +10 -11
  177. package/src/lib/window.ts +2 -3
  178. package/src/setup.ts +64 -0
  179. package/{types → src/types}/vue/index.d.ts +3 -2
  180. package/src/utils/callbackManager.ts +5 -5
  181. package/src/utils/index.ts +4 -4
  182. /package/{types → src/types}/definition.d.ts +0 -0
package/package.json CHANGED
@@ -1,11 +1,9 @@
1
1
  {
2
2
  "name": "@tarojs/taro-rn",
3
- "version": "4.0.0-beta.78",
3
+ "version": "4.0.0-beta.79",
4
4
  "description": "Taro RN framework",
5
- "author": "O2Team",
6
- "license": "MIT",
7
5
  "main": "dist/index.js",
8
- "types": "types/index.d.ts",
6
+ "typings": "types/index.d.ts",
9
7
  "files": [
10
8
  "dist",
11
9
  "src",
@@ -20,83 +18,80 @@
20
18
  "keywords": [
21
19
  "taro"
22
20
  ],
23
- "engines": {
24
- "node": ">= 18"
25
- },
21
+ "author": "O2Team",
22
+ "license": "MIT",
26
23
  "dependencies": {
27
- "@bam.tech/react-native-image-resizer": "3.0.9",
28
- "@react-native-async-storage/async-storage": "1.23.1",
29
- "@react-native-camera-roll/camera-roll": "7.7.0",
30
- "@react-native-clipboard/clipboard": "1.14.1",
31
- "@react-native-community/geolocation": "3.2.1",
32
- "@react-native-community/netinfo": "11.3.2",
33
- "base64-js": "^1.5.1",
34
- "deprecated-react-native-prop-types": "^5.0.0",
24
+ "@bam.tech/react-native-image-resizer": "~3.0.5",
25
+ "@react-native-async-storage/async-storage": "~1.21.0",
26
+ "@react-native-camera-roll/camera-roll": "~7.2.0",
27
+ "@react-native-clipboard/clipboard": "~1.13.0",
28
+ "@react-native-community/geolocation": "~3.1.0",
29
+ "@react-native-community/netinfo": "~11.2.0",
30
+ "babel-preset-expo": "~10.0.0",
31
+ "base64-js": "^1.3.0",
32
+ "deprecated-react-native-prop-types": "^2.3.0",
35
33
  "expo-av": "~13.10.0",
36
- "expo-barcode-scanner": "~13.0.1",
37
- "expo-brightness": "~12.0.1",
38
- "expo-camera": "~15.0.8",
39
- "expo-file-system": "~17.0.1",
40
- "expo-image-picker": "~15.0.4",
41
- "expo-keep-awake": "~13.0.1",
42
- "expo-location": "~17.0.1",
43
- "expo-sensors": "~13.0.6",
34
+ "expo-barcode-scanner": "~12.9.0",
35
+ "expo-brightness": "~11.8.0",
36
+ "expo-camera": "~14.0.0",
37
+ "expo-file-system": "~16.0.0",
38
+ "expo-image-picker": "~14.7.0",
39
+ "expo-keep-awake": "~12.8.0",
40
+ "expo-location": "~16.5.1",
41
+ "expo-sensors": "~12.9.0",
42
+ "nullthrows": "^1.1.1",
44
43
  "prop-types": "^15.8.1",
45
- "react-native-device-info": "11.1.0",
46
- "react-native-image-zoom-viewer": "3.0.1",
47
- "react-native-root-siblings": "5.0.1",
48
- "react-native-safe-area-context": "4.10.1",
49
- "@tarojs/taro": "4.0.0-beta.78",
50
- "@tarojs/runtime-rn": "4.0.0-beta.78"
44
+ "react-native-device-info": "~10.12.0",
45
+ "react-native-image-zoom-viewer": "^3.0.1",
46
+ "react-native-root-siblings": "^5.0.1",
47
+ "react-native-root-toast": "^3.5.1",
48
+ "react-native-safe-area-context": "~4.8.0",
49
+ "react-native-stylekit": "^1.0.0",
50
+ "@tarojs/runtime-rn": "4.0.0-beta.79"
51
51
  },
52
52
  "devDependencies": {
53
- "@babel/core": "^7.24.4",
54
- "@babel/parser": "^7.24.4",
55
- "@babel/preset-env": "^7.24.4",
56
- "@babel/traverse": "^7.24.4",
53
+ "@babel/core": "^7.23.0",
54
+ "@babel/preset-env": "^7.20.0",
57
55
  "@react-native/babel-preset": "^0.73.18",
58
56
  "@testing-library/jest-native": "^5.4.2",
59
57
  "@testing-library/react-native": "^12.4.1",
60
- "cpy-cli": "^5.0.0",
58
+ "@types/jest": "^27.4.1",
61
59
  "dpdm": "^3.14.0",
62
- "expo": "~51.0.5",
63
- "jest-expo": "^51.0.1",
60
+ "expo": "~50.0.2",
61
+ "fbjs-scripts": "^3.0.1",
62
+ "jest": "^29.3.1",
63
+ "jest-cli": "^29.3.1",
64
+ "jest-environment-node": "^29.5.0",
65
+ "jest-expo": "^50.0.0",
64
66
  "mock-socket": "^7.1.0",
65
- "react": "^18.2.0",
66
- "react-native": "^0.72.3"
67
+ "react": "18.2.0",
68
+ "react-native": "^0.73.1",
69
+ "react-test-renderer": "18.2.0"
67
70
  },
68
71
  "peerDependencies": {
69
- "@bam.tech/react-native-image-resizer": ">= 3.0.0",
70
- "@react-native-async-storage/async-storage": ">= 1.21.0",
71
- "@react-native-camera-roll/camera-roll": ">= 7.2.0",
72
- "@react-native-clipboard/clipboard": ">= 1.13.0",
73
- "@react-native-community/geolocation": ">= 3.2.0",
74
- "@react-native-community/netinfo": ">= 11.2.0",
75
- "expo": ">= 51",
76
- "expo-av": ">= 13.10.0",
77
- "expo-barcode-scanner": ">= 13",
78
- "expo-brightness": ">= 12",
79
- "expo-camera": ">= 15",
80
- "expo-file-system": ">= 17",
81
- "expo-image-picker": ">= 15",
82
- "expo-keep-awake": ">= 13",
83
- "expo-location": ">= 17",
84
- "expo-sensors": ">= 13",
85
- "react": ">= 18",
86
- "react-native": ">= 0.63.0",
87
- "react-native-device-info": ">= 11",
88
- "react-native-image-zoom-viewer": ">= 3",
89
- "react-native-root-siblings": ">= 5",
90
- "react-native-safe-area-context": ">= 4.8.0"
72
+ "@bam.tech/react-native-image-resizer": "~3.0.5",
73
+ "@react-native-async-storage/async-storage": "~1.21.0",
74
+ "@react-native-camera-roll/camera-roll": "~7.2.0",
75
+ "@react-native-clipboard/clipboard": "~1.13.0",
76
+ "@react-native-community/geolocation": "~3.1.0",
77
+ "@react-native-community/netinfo": "~11.2.0",
78
+ "expo-av": "~13.10.0",
79
+ "expo-barcode-scanner": "~12.9.0",
80
+ "expo-brightness": "~11.8.0",
81
+ "expo-camera": "~14.0.0",
82
+ "expo-file-system": "~16.0.0",
83
+ "expo-image-picker": "~14.7.0",
84
+ "expo-keep-awake": "~12.8.0",
85
+ "expo-location": "~16.5.1",
86
+ "expo-sensors": "~12.9.0",
87
+ "react-native-device-info": "~10.12.0",
88
+ "react-native-safe-area-context": "~4.8.0"
91
89
  },
92
90
  "scripts": {
93
- "prod": "pnpm run build",
94
91
  "assets": "cpy 'src/**/*.png' '!src/__tests__/*' dist",
95
- "prebuild": "pnpm run clean",
96
- "clean": "rimraf --impl=move-remove ./dist apiList.js libList.js",
97
- "build": "tsc && pnpm run assets && pnpm run script",
92
+ "build": "rimraf --impl=move-remove ./dist && tsc && pnpm run assets && pnpm run script",
98
93
  "dev": "pnpm run assets && tsc --watch",
99
- "lint": "eslint src script __tests__ --ext .js,.jsx.ts,.tsx",
94
+ "lint": "eslint .",
100
95
  "test": "jest --silent",
101
96
  "test:ci": "jest --ci -i --coverage --silent",
102
97
  "test:coverage": "jest --coverage",
@@ -0,0 +1,7 @@
1
+ const CameraRoll = {
2
+ save: jest.fn((url, { type }) => Promise.resolve(`${type}://${url}`)),
3
+ }
4
+
5
+ export default {
6
+ CameraRoll,
7
+ }
@@ -0,0 +1,13 @@
1
+ export const mockGetCurrentPosition = jest.fn()
2
+
3
+ const RNCGeolocation = {
4
+ addListener: jest.fn(),
5
+ getCurrentPosition: mockGetCurrentPosition,
6
+ removeListeners: jest.fn(),
7
+ requestAuthorization: jest.fn(),
8
+ setConfiguration: jest.fn(),
9
+ startObserving: jest.fn(),
10
+ stopObserving: jest.fn(),
11
+ }
12
+
13
+ export default RNCGeolocation
@@ -0,0 +1,154 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`scanCode should render scanCode success 1`] = `
4
+ <View
5
+ style={
6
+ [
7
+ {
8
+ "alignItems": "center",
9
+ "backgroundColor": "#FFF",
10
+ "flex": 1,
11
+ "justifyContent": "center",
12
+ "position": "absolute",
13
+ "zIndex": 1000,
14
+ },
15
+ ]
16
+ }
17
+ >
18
+ <ViewManagerAdapter_ExpoCamera
19
+ barCodeScannerEnabled={true}
20
+ barCodeScannerSettings={
21
+ {
22
+ "barCodeTypes": [],
23
+ }
24
+ }
25
+ faceDetectorSettings={{}}
26
+ focusDepth={0}
27
+ onBarCodeScanned={[Function]}
28
+ onCameraReady={[Function]}
29
+ onFacesDetected={[Function]}
30
+ onMountError={[Function]}
31
+ onPictureSaved={[Function]}
32
+ onResponsiveOrientationChanged={[Function]}
33
+ style={
34
+ {
35
+ "height": 1334,
36
+ "width": 750,
37
+ }
38
+ }
39
+ zoom={0}
40
+ />
41
+ <View
42
+ accessibilityLabel="Close"
43
+ accessibilityState={
44
+ {
45
+ "busy": undefined,
46
+ "checked": undefined,
47
+ "disabled": undefined,
48
+ "expanded": undefined,
49
+ "selected": undefined,
50
+ }
51
+ }
52
+ accessibilityValue={
53
+ {
54
+ "max": undefined,
55
+ "min": undefined,
56
+ "now": undefined,
57
+ "text": undefined,
58
+ }
59
+ }
60
+ accessible={true}
61
+ collapsable={false}
62
+ focusable={true}
63
+ onClick={[Function]}
64
+ onResponderGrant={[Function]}
65
+ onResponderMove={[Function]}
66
+ onResponderRelease={[Function]}
67
+ onResponderTerminate={[Function]}
68
+ onResponderTerminationRequest={[Function]}
69
+ onStartShouldSetResponder={[Function]}
70
+ style={
71
+ {
72
+ "left": 20,
73
+ "opacity": 1,
74
+ "position": "absolute",
75
+ "top": 10,
76
+ }
77
+ }
78
+ >
79
+ <View
80
+ style={
81
+ {
82
+ "paddingTop": 20,
83
+ }
84
+ }
85
+ >
86
+ <Image
87
+ source={1}
88
+ style={
89
+ {
90
+ "height": 25,
91
+ "marginTop": null,
92
+ "width": 25,
93
+ }
94
+ }
95
+ />
96
+ </View>
97
+ </View>
98
+ <View
99
+ accessibilityState={
100
+ {
101
+ "busy": undefined,
102
+ "checked": undefined,
103
+ "disabled": undefined,
104
+ "expanded": undefined,
105
+ "selected": undefined,
106
+ }
107
+ }
108
+ accessibilityValue={
109
+ {
110
+ "max": undefined,
111
+ "min": undefined,
112
+ "now": undefined,
113
+ "text": undefined,
114
+ }
115
+ }
116
+ accessible={true}
117
+ collapsable={false}
118
+ focusable={true}
119
+ onClick={[Function]}
120
+ onResponderGrant={[Function]}
121
+ onResponderMove={[Function]}
122
+ onResponderRelease={[Function]}
123
+ onResponderTerminate={[Function]}
124
+ onResponderTerminationRequest={[Function]}
125
+ onStartShouldSetResponder={[Function]}
126
+ style={
127
+ {
128
+ "bottom": 40,
129
+ "opacity": 1,
130
+ "position": "absolute",
131
+ "right": 20,
132
+ }
133
+ }
134
+ >
135
+ <View
136
+ style={
137
+ {
138
+ "paddingTop": 20,
139
+ }
140
+ }
141
+ >
142
+ <Image
143
+ source={1}
144
+ style={
145
+ {
146
+ "height": 20,
147
+ "width": 20,
148
+ }
149
+ }
150
+ />
151
+ </View>
152
+ </View>
153
+ </View>
154
+ `;
@@ -0,0 +1,88 @@
1
+ import Clipboard from '@react-native-clipboard/clipboard'
2
+ import { getClipboardData } from '../lib/getClipboardData'
3
+ import { setClipboardData } from '../lib/setClipboardData'
4
+
5
+ const Taro = {
6
+ setClipboardData,
7
+ getClipboardData
8
+ }
9
+
10
+ // 原生模块导出缺少 react_native_1.NativeModules.RNCClipboar setup mock
11
+
12
+ describe('clipboard', () => {
13
+ describe('setClipboardData', () => {
14
+ test('should set value into Clipboard', async () => {
15
+ const data = 'mockString'
16
+ const success = jest.fn()
17
+ const fail = jest.fn()
18
+ const complete = jest.fn()
19
+
20
+ expect.assertions(7)
21
+ const res = await Taro.setClipboardData({
22
+ data,
23
+ success,
24
+ fail,
25
+ complete
26
+ })
27
+ const expectMsg = 'setClipboardData:ok'
28
+ expect(success.mock.calls.length).toBe(1)
29
+ expect(success.mock.calls[0][0]).toEqual({ data, errMsg: expectMsg })
30
+ expect(fail.mock.calls.length).toBe(0)
31
+ expect(complete.mock.calls.length).toBe(1)
32
+ expect(complete.mock.calls[0][0]).toEqual({ data, errMsg: expectMsg })
33
+ expect(res.errMsg).toMatch(expectMsg)
34
+
35
+ const clipData = await Clipboard.getString()
36
+ expect(clipData).toEqual(data)
37
+ })
38
+
39
+ test('should fail when data is not string', () => {
40
+ const data = {}
41
+ const success = jest.fn()
42
+ const fail = jest.fn()
43
+ const complete = jest.fn()
44
+
45
+ // expect.assertions(6)
46
+ return Taro.setClipboardData({
47
+ // @ts-ignore
48
+ data,
49
+ success,
50
+ fail,
51
+ complete
52
+ }).catch(err => {
53
+ const expectErrMsg = 'setClipboardData:fail parameter error: parameter.data should be String'
54
+ expect(success.mock.calls.length).toBe(0)
55
+ expect(fail.mock.calls.length).toBe(1)
56
+ expect(fail.mock.calls[0][0]).toEqual({ errMsg: expectErrMsg })
57
+ expect(complete.mock.calls.length).toBe(1)
58
+ expect(complete.mock.calls[0][0]).toEqual({ errMsg: expectErrMsg })
59
+ expect(err.errMsg).toMatch(expectErrMsg)
60
+ })
61
+ })
62
+ })
63
+
64
+ describe('getClipboardData', () => {
65
+ test('可以获得正确的剪切板数据', async () => {
66
+ const data = 'mockString'
67
+ const success = jest.fn()
68
+ const fail = jest.fn()
69
+ const complete = jest.fn()
70
+
71
+ expect.assertions(6)
72
+ Clipboard.setString(data)
73
+
74
+ const res = await Taro.getClipboardData({
75
+ success,
76
+ fail,
77
+ complete
78
+ })
79
+ const expectErrMsg = 'getClipboardData:ok'
80
+ expect(success.mock.calls.length).toBe(1)
81
+ expect(fail.mock.calls.length).toBe(0)
82
+ expect(success.mock.calls[0][0]).toEqual({ data, errMsg: expectErrMsg })
83
+ expect(complete.mock.calls.length).toBe(1)
84
+ expect(complete.mock.calls[0][0]).toEqual({ data, errMsg: expectErrMsg })
85
+ expect(res.data).toEqual(data)
86
+ })
87
+ })
88
+ })
@@ -0,0 +1,37 @@
1
+ // import { DeviceMotion } from 'expo-sensors'
2
+ import * as Taro from '../lib/deviceMotion'
3
+
4
+ describe('deviceMotion', () => {
5
+ it('should startDeviceMotionListening success', () => {
6
+ const success = jest.fn()
7
+ const fail = jest.fn()
8
+ const complete = jest.fn()
9
+ Taro.startDeviceMotionListening({
10
+ success,
11
+ fail,
12
+ complete,
13
+ })
14
+ expect(success.mock.calls.length).toBe(1)
15
+ expect(fail.mock.calls.length).toBe(0)
16
+ expect(success.mock.calls.length).toBe(1)
17
+ })
18
+ it('should stopDeviceMotionListening success', () => {
19
+ const success = jest.fn()
20
+ const fail = jest.fn()
21
+ const complete = jest.fn()
22
+ Taro.stopDeviceMotionListening({
23
+ success,
24
+ fail,
25
+ complete,
26
+ })
27
+ expect(success.mock.calls.length).toBe(1)
28
+ expect(fail.mock.calls.length).toBe(0)
29
+ expect(success.mock.calls.length).toBe(1)
30
+ })
31
+ // it('should onDeviceMotionChange success', () => {
32
+ // const change = jest.fn().mockImplementation((ret) => {
33
+ // expect(0).toBe(0)
34
+ // })
35
+ // Taro.onDeviceMotionChange(change)
36
+ // })
37
+ })
@@ -0,0 +1,60 @@
1
+ import * as Taro from '../lib/getLocation'
2
+ import { mockGetCurrentPosition } from './__mock__/mockRNCGeolocation'
3
+
4
+ describe('location', () => {
5
+ describe('getLocation', () => {
6
+ // test('定位功能返回正常参数', () => {
7
+ // const success = jest.fn()
8
+ // const fail = jest.fn()
9
+ // const complete = jest.fn()
10
+
11
+ // const expectData = {
12
+ // latitude: expect.any(Number),
13
+ // longitude: expect.any(Number),
14
+ // speed: expect.any(Number),
15
+ // accuracy: expect.any(Number),
16
+ // altitude: expect.any(Number),
17
+ // verticalAccuracy: expect.any(Number),
18
+ // horizontalAccuracy: expect.any(Number),
19
+ // }
20
+
21
+ // expect.assertions(6)
22
+
23
+ // return Taro.getLocation({
24
+ // success,
25
+ // fail,
26
+ // complete
27
+ // }).then((res) => {
28
+ // expect(success.mock.calls.length).toBe(1)
29
+ // expect(fail.mock.calls.length).toBe(0)
30
+ // expect(complete.mock.calls.length).toBe(1)
31
+ // expect(complete.mock.calls[0][0]).toEqual(expect.objectContaining(expectData))
32
+ // expect(success.mock.calls[0][0]).toEqual(expect.objectContaining(expectData))
33
+ // expect(res).toEqual(expect.objectContaining(expectData))
34
+ // })
35
+ // })
36
+ test('定位方法正常调用', () => {
37
+ const success = jest.fn()
38
+ const fail = jest.fn()
39
+ const complete = jest.fn()
40
+
41
+ // const expectData = {
42
+ // latitude: expect.any(Number),
43
+ // longitude: expect.any(Number),
44
+ // speed: expect.any(Number),
45
+ // accuracy: expect.any(Number),
46
+ // altitude: expect.any(Number),
47
+ // verticalAccuracy: expect.any(Number),
48
+ // horizontalAccuracy: expect.any(Number),
49
+ // }
50
+
51
+ Taro.getLocation({
52
+ success,
53
+ fail,
54
+ complete
55
+ }).then(() => {
56
+ expect(mockGetCurrentPosition.mock.calls.length).toBe(1)
57
+ })
58
+ })
59
+ })
60
+ })
@@ -0,0 +1,101 @@
1
+ import React from 'react'
2
+ import { Text } from 'react-native'
3
+ import { render, fireEvent } from '@testing-library/react-native';
4
+ import ActionSheet from '../lib/showActionSheet/ActionSheet'
5
+ import Dialog from '../lib/showModal/Dialog'
6
+ import { Mask } from '../lib/Mask'
7
+ import { Popup } from '../lib/Popup'
8
+
9
+ describe('interactive', function () {
10
+ describe('showActionSheet', function () {
11
+ it('should call success callback', function () {
12
+ const onPress = jest.fn()
13
+ const { getByText, getAllByText } = render(<ActionSheet
14
+ autoDectect
15
+ type={'ios'}
16
+ visible
17
+ onClose={jest.fn()}
18
+ menus={['Option One', 'Option Two'].map((item) => {
19
+ return {
20
+ type: 'default',
21
+ label: item,
22
+ textStyle: { color: '#000000' },
23
+ onPress,
24
+ }
25
+ })}
26
+ actions={[
27
+ {
28
+ type: 'default',
29
+ label: 'cancel',
30
+ textStyle: { color: '#000000' },
31
+ onPress: jest.fn()
32
+ }
33
+ ]}
34
+ />)
35
+ expect(getAllByText('Option One')).toHaveLength(1)
36
+ expect(getAllByText('Option Two')).toHaveLength(1)
37
+ expect(getAllByText('cancel')).toHaveLength(1)
38
+ fireEvent.press(getByText('Option One'))
39
+ expect(onPress).toHaveBeenCalled();
40
+ })
41
+ })
42
+ describe('showModal', function () {
43
+ it('should render Dialog success', function () {
44
+ const { getByText } = render(<Dialog
45
+ visible
46
+ autoDectect
47
+ title='TITLE'
48
+ onClose={jest.fn()}
49
+ buttons={[
50
+ {
51
+ type: '#000000',
52
+ label: 'cancel',
53
+ onPress: jest.fn()
54
+ },
55
+ {
56
+ type: '#3CC51F',
57
+ label: 'confirm',
58
+ onPress: jest.fn()
59
+ }
60
+ ].filter(Boolean)}
61
+ ><Text>Test</Text></Dialog>)
62
+ expect(getByText('TITLE')).toHaveStyle({
63
+ fontSize: 18
64
+ })
65
+ expect(getByText('Test')).toHaveStyle({
66
+ fontSize: 15
67
+ })
68
+ expect(getByText('confirm')).toHaveStyle({
69
+ color: '#3CC51F'
70
+ })
71
+ expect(getByText('cancel')).toHaveStyle({
72
+ color: '#000000'
73
+ })
74
+ })
75
+ })
76
+ describe('Mask', () => {
77
+ it('should emit Mask event success', () => {
78
+ const onPress = jest.fn()
79
+ const { getByText, getByLabelText } = render(<Mask style={{ backgroundColor: 'red' }} onPress={onPress}><Text>Press me</Text></Mask>)
80
+ expect(getByLabelText('mask')).toHaveStyle({
81
+ backgroundColor: 'red'
82
+ })
83
+ fireEvent.press(getByText('Press me'));
84
+ expect(onPress).toHaveBeenCalled();
85
+ })
86
+ })
87
+ describe('Popup', () => {
88
+ it('should emit Popup event success', async () => {
89
+ const onShow = jest.fn()
90
+ const onClose = jest.fn()
91
+ const { getByText } = render(<Popup
92
+ visible
93
+ style={{ backgroundColor: 'red' }}
94
+ onShow={onShow}
95
+ onClose={onClose}
96
+ ><Text>Press me</Text></Popup>)
97
+ fireEvent.press(getByText('Press me'));
98
+ expect(onClose).toHaveBeenCalled();
99
+ })
100
+ })
101
+ })
@@ -0,0 +1,46 @@
1
+ import { DeviceEventEmitter } from 'react-native'
2
+ import * as Taro from '../lib/keyboard'
3
+
4
+ describe('keyboard', () => {
5
+ it('should hideKeyboard success', () => {
6
+ const success = jest.fn()
7
+ const fail = jest.fn()
8
+ const complete = jest.fn()
9
+ Taro.hideKeyboard({
10
+ success,
11
+ fail,
12
+ complete,
13
+ })
14
+ expect(success.mock.calls.length).toBe(1)
15
+ expect(fail.mock.calls.length).toBe(0)
16
+ expect(success.mock.calls.length).toBe(1)
17
+ })
18
+ it('should onKeyboardHeightChange success', () => {
19
+ expect.assertions(4)
20
+ const endCoordinates = { height: 200 }
21
+ const change = jest.fn().mockImplementation(({ height }) => expect(height).toBe(endCoordinates.height))
22
+ Taro.onKeyboardHeightChange(change)
23
+ DeviceEventEmitter.emit('keyboardDidShow', { endCoordinates })
24
+ expect(change.mock.calls.length).toBe(1)
25
+ endCoordinates.height = 0
26
+ DeviceEventEmitter.emit('keyboardDidHide', { endCoordinates })
27
+ expect(change.mock.calls.length).toBe(2)
28
+ Taro.offKeyboardHeightChange(change)
29
+ })
30
+
31
+ it('should offKeyboardHeightChange success', () => {
32
+ expect.assertions(4)
33
+ const endCoordinates = { height: 200 }
34
+ const firstChange = jest.fn()
35
+ const secondChange = jest.fn()
36
+ Taro.onKeyboardHeightChange(firstChange)
37
+ Taro.onKeyboardHeightChange(secondChange)
38
+ DeviceEventEmitter.emit('keyboardDidShow', { endCoordinates })
39
+ expect(firstChange.mock.calls.length).toBe(1)
40
+ expect(secondChange.mock.calls.length).toBe(1)
41
+ Taro.offKeyboardHeightChange(secondChange)
42
+ DeviceEventEmitter.emit('keyboardDidHide', { endCoordinates })
43
+ expect(firstChange.mock.calls.length).toBe(2)
44
+ expect(secondChange.mock.calls.length).toBe(1)
45
+ })
46
+ })