Browse Source

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>
pull/43450/head
Fly me to the moon 1 year ago
committed by GitHub
parent
commit
a998569adb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      components/date-picker/__tests__/DatePicker.test.tsx
  2. 2
      components/dropdown/__tests__/index.test.tsx
  3. 13
      tests/__mocks__/@rc-component/trigger.tsx

2
components/date-picker/__tests__/DatePicker.test.tsx

@ -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 });
}),

2
components/dropdown/__tests__/index.test.tsx

@ -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 });
}),

13
tests/__mocks__/@rc-component/trigger.tsx

@ -1,4 +1,4 @@
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';
@ -6,22 +6,21 @@ 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;

Loading…
Cancel
Save