|
|
@@ -0,0 +1,337 @@
|
|
|
+// Taro组件mock配置
|
|
|
+// 从mini/tests/setup.ts中复制的完整mock配置
|
|
|
+// 这个文件应该在其他包的jest.config.cjs中通过setupFilesAfterEnv引用
|
|
|
+
|
|
|
+import '@testing-library/jest-dom'
|
|
|
+
|
|
|
+// 扩展全局类型以支持 Taro 配置测试
|
|
|
+declare var defineAppConfig: (config: any) => any
|
|
|
+
|
|
|
+/* eslint-disable react/display-name */
|
|
|
+
|
|
|
+// 设置环境变量
|
|
|
+process.env.TARO_ENV = 'h5'
|
|
|
+process.env.TARO_PLATFORM = 'web'
|
|
|
+process.env.SUPPORT_TARO_POLYFILL = 'disabled'
|
|
|
+
|
|
|
+// 定义 defineAppConfig 全局函数用于测试 Taro 配置文件
|
|
|
+;(global as any).defineAppConfig = (config: any) => config
|
|
|
+
|
|
|
+// Mock Taro 组件
|
|
|
+// eslint-disable-next-line react/display-name
|
|
|
+jest.mock('@tarojs/components', () => {
|
|
|
+ const React = require('react')
|
|
|
+ const MockView = React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ })
|
|
|
+ MockView.displayName = 'MockView'
|
|
|
+
|
|
|
+ const MockScrollView = React.forwardRef((props: any, ref: any) => {
|
|
|
+ const {
|
|
|
+ children,
|
|
|
+ onScroll,
|
|
|
+ onTouchStart,
|
|
|
+ onScrollEnd,
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
+ scrollY,
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
+ showScrollbar,
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
+ scrollTop,
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
+ scrollWithAnimation,
|
|
|
+ ...restProps
|
|
|
+ } = props
|
|
|
+ return React.createElement('div', {
|
|
|
+ ...restProps,
|
|
|
+ ref,
|
|
|
+ onScroll: (e: any) => {
|
|
|
+ if (onScroll) onScroll(e)
|
|
|
+ },
|
|
|
+ onTouchStart: (e: any) => {
|
|
|
+ if (onTouchStart) onTouchStart(e)
|
|
|
+ },
|
|
|
+ onTouchEnd: () => {
|
|
|
+ if (onScrollEnd) onScrollEnd()
|
|
|
+ },
|
|
|
+ style: {
|
|
|
+ overflow: 'auto',
|
|
|
+ height: '200px',
|
|
|
+ ...restProps.style
|
|
|
+ }
|
|
|
+ }, children)
|
|
|
+ })
|
|
|
+ MockScrollView.displayName = 'MockScrollView'
|
|
|
+
|
|
|
+ return {
|
|
|
+ View: MockView,
|
|
|
+ ScrollView: MockScrollView,
|
|
|
+ Text: (() => {
|
|
|
+ const MockText = React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('span', { ...restProps, ref }, children)
|
|
|
+ })
|
|
|
+ MockText.displayName = 'MockText'
|
|
|
+ return MockText
|
|
|
+ })(),
|
|
|
+ Button: (() => {
|
|
|
+ const MockButton = React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('button', { ...restProps, ref }, children)
|
|
|
+ })
|
|
|
+ MockButton.displayName = 'MockButton'
|
|
|
+ return MockButton
|
|
|
+ })(),
|
|
|
+ Input: (() => {
|
|
|
+ const MockInput = React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { ...restProps } = props
|
|
|
+ return React.createElement('input', { ...restProps, ref })
|
|
|
+ })
|
|
|
+ MockInput.displayName = 'MockInput'
|
|
|
+ return MockInput
|
|
|
+ })(),
|
|
|
+ Textarea: (() => {
|
|
|
+ const MockTextarea = React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('textarea', { ...restProps, ref }, children)
|
|
|
+ })
|
|
|
+ MockTextarea.displayName = 'MockTextarea'
|
|
|
+ return MockTextarea
|
|
|
+ })(),
|
|
|
+ Image: (() => {
|
|
|
+ const MockImage = React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { ...restProps } = props
|
|
|
+ return React.createElement('img', { ...restProps, ref })
|
|
|
+ })
|
|
|
+ MockImage.displayName = 'MockImage'
|
|
|
+ return MockImage
|
|
|
+ })(),
|
|
|
+ Form: (() => {
|
|
|
+ const MockForm = React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('form', { ...restProps, ref }, children)
|
|
|
+ })
|
|
|
+ MockForm.displayName = 'MockForm'
|
|
|
+ return MockForm
|
|
|
+ })(),
|
|
|
+ Label: (() => {
|
|
|
+ const MockLabel = React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('label', { ...restProps, ref }, children)
|
|
|
+ })
|
|
|
+ MockLabel.displayName = 'MockLabel'
|
|
|
+ return MockLabel
|
|
|
+ })(),
|
|
|
+ Picker: (() => {
|
|
|
+ const MockPicker = React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ })
|
|
|
+ MockPicker.displayName = 'MockPicker'
|
|
|
+ return MockPicker
|
|
|
+ })(),
|
|
|
+ Switch: (() => {
|
|
|
+ const MockSwitch = React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { ...restProps } = props
|
|
|
+ return React.createElement('input', { type: 'checkbox', ...restProps, ref })
|
|
|
+ })
|
|
|
+ MockSwitch.displayName = 'MockSwitch'
|
|
|
+ return MockSwitch
|
|
|
+ })(),
|
|
|
+ Slider: (() => {
|
|
|
+ const MockSlider = React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { ...restProps } = props
|
|
|
+ return React.createElement('input', { type: 'range', ...restProps, ref })
|
|
|
+ })
|
|
|
+ MockSlider.displayName = 'MockSlider'
|
|
|
+ return MockSlider
|
|
|
+ })(),
|
|
|
+ Radio: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('input', { type: 'radio', ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ RadioGroup: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ Checkbox: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('input', { type: 'checkbox', ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ CheckboxGroup: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ Progress: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { ...restProps } = props
|
|
|
+ return React.createElement('progress', { ...restProps, ref })
|
|
|
+ }),
|
|
|
+ RichText: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ MovableArea: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ MovableView: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ Swiper: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ SwiperItem: React.forwardRef((props:any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ Navigator: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('a', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ Audio: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { ...restProps } = props
|
|
|
+ return React.createElement('audio', { ...restProps, ref })
|
|
|
+ }),
|
|
|
+ Video: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('video', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ Camera: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ LivePlayer: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ LivePusher: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ Map: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ Canvas: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('canvas', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ OpenData: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ WebView: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('iframe', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ Ad: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ OfficialAccount: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ CoverView: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ CoverImage: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { ...restProps } = props
|
|
|
+ return React.createElement('img', { ...restProps, ref })
|
|
|
+ }),
|
|
|
+ FunctionalPageNavigator: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ AdContent: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ MatchMedia: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ PageContainer: React.forwardRef((props: any, ref:any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ ShareElement: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ KeyboardAccessory: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ RootPortal: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ PageMeta: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ NavigationBar: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ Block: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ Import: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ Include: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ Template: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ Slot: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ NativeSlot: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ CustomWrapper: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ Editor: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ VoipRoom: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ }),
|
|
|
+ AdCustom: React.forwardRef((props: any, ref: any) => {
|
|
|
+ const { children, ...restProps } = props
|
|
|
+ return React.createElement('div', { ...restProps, ref }, children)
|
|
|
+ })
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+// Mock 常用 UI 组件
|
|
|
+jest.mock('@/components/ui/dialog', () => {
|
|
|
+ const React = require('react')
|
|
|
+ return {
|
|
|
+ Dialog: ({ open, children }: any) => open ? React.createElement('div', { 'data-testid': 'dialog' }, children) : null,
|
|
|
+ DialogContent: ({ children, className }: any) => React.createElement('div', { className }, children),
|
|
|
+ DialogHeader: ({ children, className }: any) => React.createElement('div', { className }, children),
|
|
|
+ DialogTitle: ({ children, className }: any) => React.createElement('div', { className }, children),
|
|
|
+ DialogFooter: ({ children, className }: any) => React.createElement('div', { className }, children)
|
|
|
+ }
|
|
|
+})
|
|
|
+// 默认导出
|
|
|
+export default {}
|