@tarojs/taro-rn 3.4.3 → 3.4.6

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.
@@ -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
 
@@ -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)
@@ -34,9 +34,9 @@ function _request<T = any>(options: Taro.request.Option): Taro.RequestTask<T> {
34
34
  } else {
35
35
  if (typeof data === 'object') {
36
36
  const contentType = options.header && (options.header['content-type'] || options.header['Content-Type'])
37
- if (contentType === 'application/json') {
37
+ if (contentType.startsWith('application/json')) {
38
38
  data = JSON.stringify(data)
39
- } else if (contentType === 'application/x-www-form-urlencoded') {
39
+ } else if (contentType.startsWith('application/x-www-form-urlencoded')) {
40
40
  data = serializeParams(data)
41
41
  }
42
42
  }
@@ -53,7 +53,7 @@ function _request<T = any>(options: Taro.request.Option): Taro.RequestTask<T> {
53
53
  params.method = method
54
54
  let controller
55
55
  // eslint-disable-next-line no-undef
56
- if (AbortController) {
56
+ if (typeof(AbortController) !== 'undefined' ) {
57
57
  // eslint-disable-next-line no-undef
58
58
  controller = new AbortController()
59
59
  const signal = controller.signal
@@ -182,7 +182,7 @@ export async function scanCode(option: Taro.scanCode.Option = {}): Promise<Taro.
182
182
  style={{ width, height }}
183
183
  ratio='16:9'
184
184
  />
185
- <TouchableOpacity style={styles.closeIcon} onPress={() => hide(scannerView)}>
185
+ <TouchableOpacity accessibilityLabel="Close" style={styles.closeIcon} onPress={() => hide(scannerView)}>
186
186
  {safeViewWrapper(<Image source={iconClose} style={styles.closeImg}/>)}
187
187
  </TouchableOpacity>
188
188
  {!onlyFromCamera && (<TouchableOpacity style={styles.albumIcon} onPress={() => {
package/src/setup.ts ADDED
@@ -0,0 +1,71 @@
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
+
8
+ jest.doMock('@react-native-community/netinfo', () => ({ ...mockRNCNetInfo, NetInfoStateType }))
9
+ jest.doMock('@react-native-async-storage/async-storage', () => mockRNCAsyncStorage)
10
+ jest.doMock('react-native-device-info', () => mockRNCDeviceInfo)
11
+
12
+ jest.doMock('react-native', () => {
13
+ const ReactNative = jest.requireActual('react-native') as any
14
+
15
+ // Vibration readonly so you need use defineProperty rewrite this property descriptor.
16
+ const Vibration = (jest.requireActual('./__tests__/__mock__/mockVibrate') as any).default
17
+ Object.defineProperty(ReactNative, 'Vibration', {
18
+ enumerable: false,
19
+ configurable: false,
20
+ writable: false,
21
+ value: Vibration
22
+ })
23
+
24
+ // mockNativeModules: react-native/Libraries/BatchedBridge/NativeModules
25
+ const RNCCameraRoll = (jest.requireActual('./__tests__/__mock__/mockRNCCameraRoll') as any).default
26
+ const MockClipboard = (jest.requireActual('./__tests__/__mock__/mockClipboard') as any).default
27
+ const RNCGeolocation = (jest.requireActual('./__tests__/__mock__/mockRNCGeolocation') as any).default
28
+ ReactNative.NativeModules.RNCCameraRoll = RNCCameraRoll
29
+ ReactNative.NativeModules.RNCClipboard = new MockClipboard()
30
+ ReactNative.NativeModules.RNCGeolocation = RNCGeolocation
31
+ Object.defineProperty(ReactNative.NativeModules, 'ImageLoader', {
32
+ configurable: true,
33
+ enumerable: true,
34
+ get: () => ({
35
+ prefetchImage: jest.fn(),
36
+ getSize: jest.fn((_uri, success: any) => {
37
+ process.nextTick(() => success && success(320, 240))
38
+ return Promise.resolve([320, 240])
39
+ }),
40
+ }),
41
+ })
42
+ return ReactNative
43
+ })
44
+
45
+ jest.doMock('@unimodules/core', () => {
46
+ const unimodules = jest.requireActual('@unimodules/core') as any
47
+ const permisson = jest.requireActual('./__tests__/__mock__/mockExpoPermissions')
48
+ const { NativeModulesProxy } = unimodules
49
+
50
+ NativeModulesProxy.ExpoLocation = {
51
+ getCurrentPositionAsync: jest.fn(() => Promise.resolve({
52
+ coords: {
53
+ latitude: 0,
54
+ longitude: 0,
55
+ speed: 0,
56
+ accuracy: 0,
57
+ altitude: 0
58
+ }
59
+ }))
60
+ }
61
+ NativeModulesProxy.ExpoPermissions = permisson
62
+
63
+ return unimodules
64
+ })
65
+
66
+ jest.doMock('react-native-unimodules', () => {
67
+ const unimodules = jest.requireActual('react-native-unimodules') as any
68
+ const permisson = jest.requireActual('./__tests__/__mock__/mockExpoPermissions')
69
+ unimodules.Permissions = permisson
70
+ return unimodules
71
+ })