ant-design/tests/__mocks__/rc-trigger.tsx

28 lines
817 B
TypeScript
Raw Normal View History

2022-12-19 13:31:41 +08:00
import type { TriggerProps } from 'rc-trigger';
import MockTrigger from 'rc-trigger/lib/mock';
import * as React from 'react';
import { TriggerMockContext } from '../shared/demoTestContext';
let OriginTrigger = jest.requireActual('rc-trigger');
OriginTrigger = OriginTrigger.default ?? OriginTrigger;
2022-12-19 13:31:41 +08:00
const ForwardTrigger = React.forwardRef<any, TriggerProps>((props, ref) => {
const context = React.useContext(TriggerMockContext);
const mergedPopupVisible = context?.popupVisible ?? props.popupVisible;
2022-12-19 13:31:41 +08:00
(global as any).triggerProps = props;
const mergedProps = {
...props,
ref,
popupVisible: mergedPopupVisible as boolean,
};
if (context?.mock === false) {
return <OriginTrigger {...mergedProps} />;
}
return <MockTrigger {...mergedProps} />;
});
2022-12-19 13:31:41 +08:00
export default ForwardTrigger;