Skip to content

Commit df4c12d

Browse files
author
zhuqingan.3
committed
fix: 补全单元测试缺失的api
1 parent b5b488e commit df4c12d

File tree

1 file changed

+24
-0
lines changed
  • packages/taro-components-react/__tests__

1 file changed

+24
-0
lines changed

packages/taro-components-react/__tests__/setup.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ process.env.TARO_ENV = 'h5'
77
process.env.TARO_PLATFORM = 'web'
88
process.env.SUPPORT_TARO_POLYFILL = 'disabled'
99

10+
// Mock Taro API
11+
const mockGetSystemInfo = jest.fn(({ success, fail } = { success: undefined, fail: undefined }) => {
12+
try {
13+
success?.({
14+
windowWidth: 375,
15+
windowHeight: 667,
16+
pixelRatio: 2,
17+
lengthScaleRatio: 1
18+
})
19+
} catch (error) {
20+
fail?.(error)
21+
}
22+
})
23+
24+
jest.mock('@tarojs/taro', () => {
25+
return {
26+
__esModule: true,
27+
default: {
28+
getSystemInfo: mockGetSystemInfo,
29+
},
30+
getSystemInfo: mockGetSystemInfo,
31+
}
32+
})
33+
1034
// Mock Taro 组件
1135
// eslint-disable-next-line react/display-name
1236
jest.mock('@tarojs/components', () => {

0 commit comments

Comments
 (0)