@tarojs/taro-rn 3.4.2 → 3.4.5

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 (55) hide show
  1. package/dist/lib/Mask.js +1 -1
  2. package/dist/lib/Mask.js.map +1 -1
  3. package/dist/lib/Popup.js +3 -2
  4. package/dist/lib/Popup.js.map +1 -1
  5. package/dist/lib/chooseVideo/index.js +1 -1
  6. package/dist/lib/chooseVideo/index.js.map +1 -1
  7. package/dist/lib/connectSocket/index.js +0 -1
  8. package/dist/lib/connectSocket/index.js.map +1 -1
  9. package/dist/lib/connectSocket/socketTask.js +2 -2
  10. package/dist/lib/connectSocket/socketTask.js.map +1 -1
  11. package/dist/lib/createInnerAudioContext/index.js +10 -10
  12. package/dist/lib/createInnerAudioContext/index.js.map +1 -1
  13. package/dist/lib/file.js +2 -1
  14. package/dist/lib/file.js.map +1 -1
  15. package/dist/lib/getLocation/index.js +1 -1
  16. package/dist/lib/getLocation/index.js.map +1 -1
  17. package/dist/lib/location.js +1 -1
  18. package/dist/lib/location.js.map +1 -1
  19. package/dist/lib/permission.js +1 -1
  20. package/dist/lib/permission.js.map +1 -1
  21. package/dist/lib/request/index.js +4 -4
  22. package/dist/lib/request/index.js.map +1 -1
  23. package/dist/lib/scanCode/index.js +1 -1
  24. package/dist/lib/scanCode/index.js.map +1 -1
  25. package/dist/lib/showModal/toast.js +9 -8
  26. package/dist/lib/showModal/toast.js.map +1 -1
  27. package/dist/setup.js +64 -0
  28. package/dist/setup.js.map +1 -0
  29. package/package.json +12 -14
  30. package/src/__tests__/__mock__/mockAsyncStorage.js +0 -1
  31. package/src/__tests__/__mock__/mockExpoPermissions.js +1 -1
  32. package/src/__tests__/__snapshots__/scanCode.test.js.snap +113 -0
  33. package/src/__tests__/interactive.test.js +40 -66
  34. package/src/__tests__/keyboard.test.js +6 -6
  35. package/src/__tests__/request.test.js +1 -1
  36. package/src/__tests__/scanCode.test.js +14 -0
  37. package/src/__tests__/storage.test.js +1 -1
  38. package/src/__tests__/system.test.js +8 -8
  39. package/src/lib/Mask.tsx +1 -0
  40. package/src/lib/Popup.tsx +2 -2
  41. package/src/lib/chooseVideo/index.ts +1 -1
  42. package/src/lib/connectSocket/index.ts +0 -1
  43. package/src/lib/connectSocket/socketTask.ts +2 -2
  44. package/src/lib/createInnerAudioContext/index.ts +10 -10
  45. package/src/lib/file.ts +2 -1
  46. package/src/lib/getLocation/index.ts +1 -1
  47. package/src/lib/location.ts +1 -1
  48. package/src/lib/permission.ts +1 -1
  49. package/src/lib/request/index.ts +4 -4
  50. package/src/lib/scanCode/index.tsx +1 -1
  51. package/src/lib/showModal/toast.tsx +10 -8
  52. package/src/setup.ts +71 -0
  53. package/src/types/definition.d.ts +2 -0
  54. package/src/__tests__/__snapshots__/interactive.test.js.snap +0 -1690
  55. package/src/__tests__/scanCode.test_.js +0 -24
package/dist/setup.js ADDED
@@ -0,0 +1,64 @@
1
+ import { jest } from '@jest/globals';
2
+ import '@testing-library/jest-native/extend-expect';
3
+ import mockRNCNetInfo from '@react-native-community/netinfo/jest/netinfo-mock.js';
4
+ import { NetInfoStateType } from '@react-native-community/netinfo';
5
+ import mockRNCAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock.js';
6
+ import mockRNCDeviceInfo from 'react-native-device-info/jest/react-native-device-info-mock';
7
+ jest.doMock('@react-native-community/netinfo', () => (Object.assign(Object.assign({}, mockRNCNetInfo), { NetInfoStateType })));
8
+ jest.doMock('@react-native-async-storage/async-storage', () => mockRNCAsyncStorage);
9
+ jest.doMock('react-native-device-info', () => mockRNCDeviceInfo);
10
+ jest.doMock('react-native', () => {
11
+ const ReactNative = jest.requireActual('react-native');
12
+ // Vibration readonly so you need use defineProperty rewrite this property descriptor.
13
+ const Vibration = jest.requireActual('./__tests__/__mock__/mockVibrate').default;
14
+ Object.defineProperty(ReactNative, 'Vibration', {
15
+ enumerable: false,
16
+ configurable: false,
17
+ writable: false,
18
+ value: Vibration
19
+ });
20
+ // mockNativeModules: react-native/Libraries/BatchedBridge/NativeModules
21
+ const RNCCameraRoll = jest.requireActual('./__tests__/__mock__/mockRNCCameraRoll').default;
22
+ const MockClipboard = jest.requireActual('./__tests__/__mock__/mockClipboard').default;
23
+ const RNCGeolocation = jest.requireActual('./__tests__/__mock__/mockRNCGeolocation').default;
24
+ ReactNative.NativeModules.RNCCameraRoll = RNCCameraRoll;
25
+ ReactNative.NativeModules.RNCClipboard = new MockClipboard();
26
+ ReactNative.NativeModules.RNCGeolocation = RNCGeolocation;
27
+ Object.defineProperty(ReactNative.NativeModules, 'ImageLoader', {
28
+ configurable: true,
29
+ enumerable: true,
30
+ get: () => ({
31
+ prefetchImage: jest.fn(),
32
+ getSize: jest.fn((_uri, success) => {
33
+ process.nextTick(() => success && success(320, 240));
34
+ return Promise.resolve([320, 240]);
35
+ }),
36
+ }),
37
+ });
38
+ return ReactNative;
39
+ });
40
+ jest.doMock('@unimodules/core', () => {
41
+ const unimodules = jest.requireActual('@unimodules/core');
42
+ const permisson = jest.requireActual('./__tests__/__mock__/mockExpoPermissions');
43
+ const { NativeModulesProxy } = unimodules;
44
+ NativeModulesProxy.ExpoLocation = {
45
+ getCurrentPositionAsync: jest.fn(() => Promise.resolve({
46
+ coords: {
47
+ latitude: 0,
48
+ longitude: 0,
49
+ speed: 0,
50
+ accuracy: 0,
51
+ altitude: 0
52
+ }
53
+ }))
54
+ };
55
+ NativeModulesProxy.ExpoPermissions = permisson;
56
+ return unimodules;
57
+ });
58
+ jest.doMock('react-native-unimodules', () => {
59
+ const unimodules = jest.requireActual('react-native-unimodules');
60
+ const permisson = jest.requireActual('./__tests__/__mock__/mockExpoPermissions');
61
+ unimodules.Permissions = permisson;
62
+ return unimodules;
63
+ });
64
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,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,OAAO,UAAU,CAAA;AACnB,CAAC,CAAC,CAAA;AAEF,IAAI,CAAC,MAAM,CAAC,yBAAyB,EAAE,GAAG,EAAE;IAC1C,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAQ,CAAA;IACvE,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC,CAAA;IAChF,UAAU,CAAC,WAAW,GAAG,SAAS,CAAA;IAClC,OAAO,UAAU,CAAA;AACnB,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/taro-rn",
3
- "version": "3.4.2",
3
+ "version": "3.4.5",
4
4
  "description": "Taro RN framework",
5
5
  "main": "dist/index.js",
6
6
  "typings": "types/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "lint": "eslint .",
19
19
  "test": "jest --silent",
20
20
  "test:dev": "jest --watch",
21
- "test:ci": "jest --silent -i --coverage false",
21
+ "test:ci": "jest -i --silent --coverage false",
22
22
  "test:coverage": "jest --coverage",
23
23
  "script": "node ./script"
24
24
  },
@@ -37,7 +37,7 @@
37
37
  "@react-native-community/clipboard": "~1.5.1",
38
38
  "@react-native-community/geolocation": "~2.0.2",
39
39
  "@react-native-community/netinfo": "~7.1.2",
40
- "@tarojs/runtime-rn": "3.4.2",
40
+ "@tarojs/runtime-rn": "3.4.5",
41
41
  "babel-preset-expo": "~8.5.1",
42
42
  "base64-js": "^1.3.0",
43
43
  "expo-av": "~9.2.3",
@@ -55,19 +55,17 @@
55
55
  "react-native-image-zoom-viewer": "^3.0.1",
56
56
  "react-native-root-siblings": "^4.1.1",
57
57
  "react-native-root-toast": "^3.0.1",
58
- "react-native-safe-area-context": "~3.3.2",
58
+ "react-native-safe-area-context": "~3.4.1",
59
59
  "react-native-stylekit": "^1.0.0",
60
- "react-native-syan-image-picker": "0.5.3",
61
- "react-native-unimodules": "~0.14.10"
60
+ "react-native-syan-image-picker": "0.5.3"
62
61
  },
63
62
  "devDependencies": {
64
- "@tarojs/taro": "3.4.2",
65
- "@types/react-native": "0.66.5",
66
- "babel-plugin-jest-hoist": "^26.6.2",
63
+ "@tarojs/taro": "3.4.5",
64
+ "@types/react-native": "0.67.0",
67
65
  "cpy-cli": "^3.1.1",
68
- "jest-expo": "^39.0.0",
69
- "react-native": "^0.66.0",
70
- "rimraf": "^3.0.0"
66
+ "fbjs-scripts": "^3.0.1",
67
+ "react-native": "^0.67.3",
68
+ "react-native-unimodules": "~0.14.10"
71
69
  },
72
70
  "peerDependencies": {
73
71
  "@react-native-async-storage/async-storage": "~1.15.11",
@@ -86,7 +84,7 @@
86
84
  "expo-sensors": "~10.2.2",
87
85
  "react-native-device-info": "~8.4.8",
88
86
  "react-native-image-resizer": "~1.4.5",
89
- "react-native-safe-area-context": "~3.3.2",
87
+ "react-native-safe-area-context": "~3.4.1",
90
88
  "react-native-syan-image-picker": "0.5.3",
91
89
  "react-native-unimodules": "~0.14.10"
92
90
  },
@@ -94,5 +92,5 @@
94
92
  "@types/react": "17.0.11",
95
93
  "@types/node": "^14.14.41"
96
94
  },
97
- "gitHead": "26b329326c6a7da652e8d712ee33df01ab8d2d0e"
95
+ "gitHead": "789e873f7b9477124b44a900cd4f6a2810e4e06a"
98
96
  }
@@ -22,7 +22,6 @@ export default class MockStorage {
22
22
 
23
23
  removeItem = jest.fn((key) => {
24
24
  return new Promise((resolve, reject) => {
25
- // eslint-disable-next-line
26
25
  return this.storageCache.hasOwnProperty(key)
27
26
  ? resolve(delete this.storageCache[key])
28
27
  : reject(new Error('No such key!'))
@@ -1,5 +1,5 @@
1
1
  export const CAMERA = 'camera'
2
- export const CAMERA_ROLL = 'cameraRoll'
2
+ export const CAMERA_ROLL = 'mediaLibrary'
3
3
  export const LOCATION = 'location'
4
4
  export const askAsync = jest.fn().mockImplementation((permissionType) => {
5
5
  const hasPermission = [CAMERA, CAMERA_ROLL, LOCATION].includes(permissionType)
@@ -0,0 +1,113 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`scanCode should render scanCode success 1`] = `
4
+ <View
5
+ style={
6
+ Array [
7
+ Object {
8
+ "alignItems": "center",
9
+ "backgroundColor": "#FFF",
10
+ "flex": 1,
11
+ "justifyContent": "center",
12
+ "position": "absolute",
13
+ "zIndex": 1000,
14
+ },
15
+ ]
16
+ }
17
+ >
18
+ <ViewManagerAdapter_ExponentCamera
19
+ proxiedProperties={
20
+ Object {
21
+ "autoFocus": undefined,
22
+ "barCodeScannerEnabled": true,
23
+ "barCodeScannerSettings": Object {
24
+ "barCodeTypes": Array [],
25
+ },
26
+ "faceDetectorSettings": Object {},
27
+ "flashMode": undefined,
28
+ "focusDepth": 0,
29
+ "onBarCodeScanned": [Function],
30
+ "onCameraReady": [Function],
31
+ "onFacesDetected": [Function],
32
+ "onMountError": [Function],
33
+ "onPictureSaved": [Function],
34
+ "type": undefined,
35
+ "whiteBalance": undefined,
36
+ "zoom": 0,
37
+ }
38
+ }
39
+ style={
40
+ Object {
41
+ "height": 1334,
42
+ "width": 750,
43
+ }
44
+ }
45
+ />
46
+ <View
47
+ accessibilityLabel="Close"
48
+ accessible={true}
49
+ collapsable={false}
50
+ focusable={true}
51
+ onClick={[Function]}
52
+ onResponderGrant={[Function]}
53
+ onResponderMove={[Function]}
54
+ onResponderRelease={[Function]}
55
+ onResponderTerminate={[Function]}
56
+ onResponderTerminationRequest={[Function]}
57
+ onStartShouldSetResponder={[Function]}
58
+ style={
59
+ Object {
60
+ "left": 20,
61
+ "opacity": 1,
62
+ "position": "absolute",
63
+ "top": 10,
64
+ }
65
+ }
66
+ >
67
+ <RNCSafeAreaView>
68
+ <Image
69
+ source={1}
70
+ style={
71
+ Object {
72
+ "height": 25,
73
+ "marginTop": null,
74
+ "width": 25,
75
+ }
76
+ }
77
+ />
78
+ </RNCSafeAreaView>
79
+ </View>
80
+ <View
81
+ accessible={true}
82
+ collapsable={false}
83
+ focusable={true}
84
+ onClick={[Function]}
85
+ onResponderGrant={[Function]}
86
+ onResponderMove={[Function]}
87
+ onResponderRelease={[Function]}
88
+ onResponderTerminate={[Function]}
89
+ onResponderTerminationRequest={[Function]}
90
+ onStartShouldSetResponder={[Function]}
91
+ style={
92
+ Object {
93
+ "bottom": 40,
94
+ "opacity": 1,
95
+ "position": "absolute",
96
+ "right": 20,
97
+ }
98
+ }
99
+ >
100
+ <RNCSafeAreaView>
101
+ <Image
102
+ source={1}
103
+ style={
104
+ Object {
105
+ "height": 20,
106
+ "width": 20,
107
+ }
108
+ }
109
+ />
110
+ </RNCSafeAreaView>
111
+ </View>
112
+ </View>
113
+ `;
@@ -1,8 +1,6 @@
1
- // eslint-disable-next-line
2
1
  import React from 'react'
3
- import { TouchableHighlight, Text } from 'react-native'
4
- import { mount } from 'enzyme'
5
- import toJson from 'enzyme-to-json'
2
+ import { Text } from 'react-native'
3
+ import { render, fireEvent } from '@testing-library/react-native';
6
4
  import ActionSheet from '../lib/showActionSheet/ActionSheet'
7
5
  import Dialog from '../lib/showModal/Dialog'
8
6
  import { Mask } from '../lib/Mask'
@@ -10,118 +8,94 @@ import { Popup } from '../lib/Popup'
10
8
 
11
9
  describe('interactive', function () {
12
10
  describe('showActionSheet', function () {
13
- it('should render ActionSheet success', function () {
14
- const wrapper = mount(<ActionSheet
15
- autoDectect
16
- type={'ios'}
17
- visible={false}
18
- onClose={jest.fn()}
19
- menus={['选项一', '选项二'].map((item) => {
20
- return {
21
- type: 'default',
22
- label: item,
23
- textStyle: { color: '#000000' },
24
- onPress: jest.fn()
25
- }
26
- })}
27
- actions={[
28
- {
29
- type: 'default',
30
- label: '取消',
31
- textStyle: { color: '#000000' },
32
- onPress: jest.fn()
33
- }
34
- ]}
35
- />)
36
- expect(toJson(wrapper)).toMatchSnapshot()
37
- })
38
11
  it('should call success callback', function () {
39
- const success = jest.fn()
40
- const wrapper = mount(<ActionSheet
12
+ const onPress = jest.fn()
13
+ const { getByText, getAllByText } = render(<ActionSheet
41
14
  autoDectect
42
15
  type={'ios'}
43
16
  visible
44
17
  onClose={jest.fn()}
45
- menus={['选项一', '选项二'].map((item) => {
18
+ menus={['Option One', 'Option Two'].map((item) => {
46
19
  return {
47
20
  type: 'default',
48
21
  label: item,
49
22
  textStyle: { color: '#000000' },
50
- onPress: success
23
+ onPress,
51
24
  }
52
25
  })}
53
26
  actions={[
54
27
  {
55
28
  type: 'default',
56
- label: '取消',
29
+ label: 'cancel',
57
30
  textStyle: { color: '#000000' },
58
31
  onPress: jest.fn()
59
32
  }
60
33
  ]}
61
34
  />)
62
- // expect(wrapper.find(TouchableHighlight).at(0)).toBe(1)
63
- wrapper.find(TouchableHighlight).first().props().onPress()
64
- expect(success.mock.calls.length).toBe(1)
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();
65
40
  })
66
41
  })
67
42
  describe('showModal', function () {
68
43
  it('should render Dialog success', function () {
69
- const wrapper = mount(<Dialog
44
+ const { getByText } = render(<Dialog
70
45
  visible
71
46
  autoDectect
72
- title='title'
47
+ title='TITLE'
73
48
  onClose={jest.fn()}
74
49
  buttons={[
75
50
  {
76
51
  type: '#000000',
77
- label: '取消',
52
+ label: 'cancel',
78
53
  onPress: jest.fn()
79
54
  },
80
55
  {
81
56
  type: '#3CC51F',
82
- label: '确定',
57
+ label: 'confirm',
83
58
  onPress: jest.fn()
84
59
  }
85
60
  ].filter(Boolean)}
86
61
  ><Text>Test</Text></Dialog>)
87
- expect(toJson(wrapper)).toMatchSnapshot()
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
+ })
88
74
  })
89
75
  })
90
76
  describe('Mask', () => {
91
- it('should render Mask success', () => {
92
- const wrapper = mount(<Mask style={{ color: 'red' }} onPress={jest.fn()}><Text>Test</Text></Mask>)
93
- expect(toJson(wrapper)).toMatchSnapshot()
94
- })
95
77
  it('should emit Mask event success', () => {
96
78
  const onPress = jest.fn()
97
- const wrapper = mount(<Mask style={{ color: 'red' }} onPress={onPress}><Text>Test</Text></Mask>)
98
- wrapper.find(Mask).first().props().onPress()
99
- expect(onPress.call.length).toBe(1)
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();
100
85
  })
101
86
  })
102
87
  describe('Popup', () => {
103
- it('should render Popup success', () => {
104
- const onShow = jest.fn()
105
- const onClose = jest.fn()
106
- const wrapper = mount(<Popup
107
- style={{ color: 'red' }}
108
- onShow={onShow}
109
- onClose={onClose}
110
- ><Text>Test</Text></Popup>)
111
- expect(toJson(wrapper)).toMatchSnapshot()
112
- })
113
- it('should emit Popup event success', () => {
88
+ it('should emit Popup event success', async () => {
114
89
  const onShow = jest.fn()
115
90
  const onClose = jest.fn()
116
- const wrapper = mount(<Popup
91
+ const { getByText } = render(<Popup
117
92
  visible
118
- style={{ color: 'red' }}
93
+ style={{ backgroundColor: 'red' }}
119
94
  onShow={onShow}
120
95
  onClose={onClose}
121
- ><Text>Test</Text></Popup>)
122
- expect(onShow.call.length).toBe(1)
123
- wrapper.find(Mask).at(0).props().onPress()
124
- expect(onClose.call.length).toBe(1)
96
+ ><Text>Press me</Text></Popup>)
97
+ fireEvent.press(getByText('Press me'));
98
+ expect(onClose).toHaveBeenCalled();
125
99
  })
126
100
  })
127
101
  })
@@ -1,4 +1,4 @@
1
- import { Keyboard } from 'react-native'
1
+ import { DeviceEventEmitter } from 'react-native'
2
2
  import * as Taro from '../lib/keyboard'
3
3
 
4
4
  describe('keyboard', () => {
@@ -18,12 +18,12 @@ describe('keyboard', () => {
18
18
  it('should onKeyboardHeightChange success', () => {
19
19
  expect.assertions(4)
20
20
  const endCoordinates = { height: 200 }
21
- const change = jest.fn().mockImplementation(height => expect(height).toBe(endCoordinates.height))
21
+ const change = jest.fn().mockImplementation(({ height }) => expect(height).toBe(endCoordinates.height))
22
22
  Taro.onKeyboardHeightChange(change)
23
- Keyboard.emit('keyboardDidShow', { endCoordinates })
23
+ DeviceEventEmitter.emit('keyboardDidShow', { endCoordinates })
24
24
  expect(change.mock.calls.length).toBe(1)
25
25
  endCoordinates.height = 0
26
- Keyboard.emit('keyboardDidHide', { endCoordinates })
26
+ DeviceEventEmitter.emit('keyboardDidHide', { endCoordinates })
27
27
  expect(change.mock.calls.length).toBe(2)
28
28
  Taro.offKeyboardHeightChange(change)
29
29
  })
@@ -35,11 +35,11 @@ describe('keyboard', () => {
35
35
  const secondChange = jest.fn()
36
36
  Taro.onKeyboardHeightChange(firstChange)
37
37
  Taro.onKeyboardHeightChange(secondChange)
38
- Keyboard.emit('keyboardDidShow', { endCoordinates })
38
+ DeviceEventEmitter.emit('keyboardDidShow', { endCoordinates })
39
39
  expect(firstChange.mock.calls.length).toBe(1)
40
40
  expect(secondChange.mock.calls.length).toBe(1)
41
41
  Taro.offKeyboardHeightChange(secondChange)
42
- Keyboard.emit('keyboardDidHide', { endCoordinates })
42
+ DeviceEventEmitter.emit('keyboardDidHide', { endCoordinates })
43
43
  expect(firstChange.mock.calls.length).toBe(2)
44
44
  expect(secondChange.mock.calls.length).toBe(1)
45
45
  })
@@ -110,7 +110,7 @@ describe('request', () => {
110
110
  method: 'post',
111
111
  dataType: 'json',
112
112
  header: {
113
- 'content-type': 'application/json'
113
+ 'content-type': 'application/json;charset=UTF-8'
114
114
  },
115
115
  data: {
116
116
  a: 1
@@ -0,0 +1,14 @@
1
+ // eslint-disable-next-line
2
+ import React from 'react'
3
+ import { RootSiblingParent } from 'react-native-root-siblings';
4
+ import { render, waitFor } from '@testing-library/react-native';
5
+ import { scanCode } from '../lib/scanCode'
6
+
7
+ describe('scanCode', () => {
8
+ it('should render scanCode success', async () => {
9
+ const { toJSON, getByLabelText } = render(<RootSiblingParent />)
10
+ scanCode()
11
+ await waitFor(() => getByLabelText('Close'));
12
+ expect(toJSON()).toMatchSnapshot()
13
+ })
14
+ })
@@ -63,7 +63,7 @@ describe('storage', () => {
63
63
  fail,
64
64
  complete
65
65
  }).catch(err => {
66
- const expectErrMsg = err.message
66
+ const expectErrMsg = err.errMsg
67
67
  expect(fail.mock.calls.length).toBe(1)
68
68
  expect(fail.mock.calls[0][0]).toEqual({ errMsg: expectErrMsg })
69
69
  expect(complete.mock.calls.length).toBe(1)
@@ -7,8 +7,8 @@ describe('system', () => {
7
7
  describe('getSystemInfoSync', () => {
8
8
  test('能同步返回正确的系统信息', () => {
9
9
  const expectRes = {
10
- brand: null,
11
- model: null,
10
+ brand: expect.any(String),
11
+ model: expect.any(String),
12
12
  pixelRatio: expect.any(Number),
13
13
  safeArea: expect.any(Object),
14
14
  screenWidth: expect.any(Number),
@@ -17,8 +17,8 @@ describe('system', () => {
17
17
  windowHeight: expect.any(Number),
18
18
  statusBarHeight: expect.any(Number),
19
19
  language: null,
20
- version: null,
21
- system: undefined,
20
+ version: expect.any(String),
21
+ system: expect.any(String),
22
22
  platform: expect.any(String),
23
23
  fontSizeSetting: expect.any(Number),
24
24
  SDKVersion: null
@@ -35,8 +35,8 @@ describe('system', () => {
35
35
  const fail = jest.fn()
36
36
  const complete = jest.fn()
37
37
  const expectRes = {
38
- brand: null,
39
- model: null,
38
+ brand: expect.any(String),
39
+ model: expect.any(String),
40
40
  pixelRatio: expect.any(Number),
41
41
  safeArea: expect.any(Object),
42
42
  screenWidth: expect.any(Number),
@@ -45,8 +45,8 @@ describe('system', () => {
45
45
  windowHeight: expect.any(Number),
46
46
  statusBarHeight: expect.any(Number),
47
47
  language: null,
48
- version: null,
49
- system: undefined,
48
+ version: expect.any(String),
49
+ system: expect.any(String),
50
50
  platform: expect.any(String),
51
51
  fontSizeSetting: expect.any(Number),
52
52
  SDKVersion: null
package/src/lib/Mask.tsx CHANGED
@@ -12,6 +12,7 @@ const styles = StyleSheet.create({
12
12
  const Mask: React.FC<any> = ({ transparent = false, style, onPress, children }) =>
13
13
  <TouchableWithoutFeedback onPress={onPress}>
14
14
  <View
15
+ accessibilityLabel='mask'
15
16
  style={[styles.mask, { backgroundColor: transparent ? 'transparent' : 'rgba(0,0,0,.6)' }, style]}
16
17
  >
17
18
  <TouchableWithoutFeedback>{children}</TouchableWithoutFeedback>
package/src/lib/Popup.tsx CHANGED
@@ -34,7 +34,7 @@ class Popup extends Component<any, any> {
34
34
 
35
35
  constructor (props:Props) {
36
36
  super(props)
37
- this.state = { visible: false, translateY: new Animated.Value(height) }
37
+ this.state = { visible: props.visible ?? false, translateY: new Animated.Value(height) }
38
38
  this.handleLayout = this.handleLayout.bind(this)
39
39
  }
40
40
 
@@ -54,7 +54,7 @@ class Popup extends Component<any, any> {
54
54
  }
55
55
 
56
56
  handleLayout ():void {
57
- this.popup.measure((x, y, w, h) => {
57
+ this.popup.measure((_x, _y, _w, h) => {
58
58
  this.height = h
59
59
  this.setState({ translateY: new Animated.Value(h) })
60
60
  Animated.timing(this.state.translateY, {
@@ -43,7 +43,7 @@ function showVideoPicker(options: Taro.chooseVideo.Option):any {
43
43
  resolve(chooseMedia({...options, sourceType: ['album']}, MEDIA_TYPE.VIDEOS))
44
44
  }
45
45
  },
46
- fail: function (err) {
46
+ fail: function () {
47
47
  const res = { errMsg: 'chooseVideo:fail cancel' }
48
48
  reject(res)
49
49
  }
@@ -25,7 +25,6 @@ export function connectSocket(opts: Taro.connectSocket.Option): Promise<Taro.Soc
25
25
  if (socketTasks.length >= 2) {
26
26
  const error = new Error('同时最多发起 2 个 socket 请求,更多请参考文档。')
27
27
  res.errMsg = error.message
28
- console.error(res.errMsg)
29
28
  fail?.(res)
30
29
  complete?.(res)
31
30
  return reject(res)
@@ -87,9 +87,9 @@ class SocketTask {
87
87
  }
88
88
 
89
89
  onError (func?: Taro.SocketTask.OnErrorCallback): void {
90
- this.ws.onerror = (res) => {
90
+ this.ws.onerror = () => {
91
91
  func && func({
92
- errMsg: res.message
92
+ errMsg: "There was an error with your websocket.",
93
93
  })
94
94
  }
95
95
  }