ant-design/tests/__mocks__/@rc-component/trigger.tsx
Fly me to the moon a998569adb
test: optimization type in test case (#43449)
* test: optimization type in test case

* fix lint

---------

Co-authored-by: 我们去月球漫步 <13105694+flymetothemoon-wj@user.noreply.gitee.com>
2023-07-08 15:45:28 +08:00

27 lines
886 B
TypeScript

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