Skip to content

Commit

Permalink
test: optimization type in test case (ant-design#43449)
Browse files Browse the repository at this point in the history
* test: optimization type in test case

* fix lint

---------

Co-authored-by: 我们去月球漫步 <[email protected]>
  • Loading branch information
Negentropy247 and 我们去月球漫步 authored Jul 8, 2023
1 parent 9b03ce4 commit a998569
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/date-picker/__tests__/DatePicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jest.mock('@rc-component/trigger', () => {
const h: typeof React = jest.requireActual('react');

return {
default: h.forwardRef<unknown, TriggerProps>((props, ref) => {
default: h.forwardRef<HTMLElement, TriggerProps>((props, ref) => {
triggerProps = props;
return h.createElement(Trigger, { ref, ...props });
}),
Expand Down
2 changes: 1 addition & 1 deletion components/dropdown/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jest.mock('@rc-component/trigger', () => {
const h: typeof React = jest.requireActual('react');

return {
default: h.forwardRef<unknown, TriggerProps>((props, ref) => {
default: h.forwardRef<HTMLElement, TriggerProps>((props, ref) => {
triggerProps = props;
return h.createElement(Trigger, { ref, ...props });
}),
Expand Down
13 changes: 6 additions & 7 deletions tests/__mocks__/@rc-component/trigger.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import type { TriggerProps } from '@rc-component/trigger';
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<any, TriggerProps>((props, ref) => {
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 = {
const mergedProps: TriggerProps = {
...props,
ref,
popupVisible: mergedPopupVisible as boolean,
popupVisible: mergedPopupVisible,
};

if (context?.mock === false) {
return <OriginTrigger {...mergedProps} />;
return <OriginTrigger ref={ref} {...mergedProps} />;
}
return <MockTrigger {...mergedProps} />;
return <MockTrigger ref={ref} {...mergedProps} />;
});

export default ForwardTrigger;

0 comments on commit a998569

Please sign in to comment.