From 3276e7b75c018de81244051fd62fa40f615a5c50 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Mon, 19 Dec 2022 13:31:41 +0800 Subject: [PATCH] test: js => ts (#39642) --- tests/__mocks__/copy-to-clipboard.js | 6 ------ tests/__mocks__/copy-to-clipboard.ts | 9 +++++++++ tests/__mocks__/{rc-trigger.js => rc-trigger.tsx} | 9 ++++++--- tests/__mocks__/rc-util/lib/{Portal.js => Portal.ts} | 6 +++++- .../__mocks__/{rc-virtual-list.js => rc-virtual-list.ts} | 0 5 files changed, 20 insertions(+), 10 deletions(-) delete mode 100644 tests/__mocks__/copy-to-clipboard.js create mode 100644 tests/__mocks__/copy-to-clipboard.ts rename tests/__mocks__/{rc-trigger.js => rc-trigger.tsx} (57%) rename tests/__mocks__/rc-util/lib/{Portal.js => Portal.ts} (71%) rename tests/__mocks__/{rc-virtual-list.js => rc-virtual-list.ts} (100%) diff --git a/tests/__mocks__/copy-to-clipboard.js b/tests/__mocks__/copy-to-clipboard.js deleted file mode 100644 index 8e79b83183..0000000000 --- a/tests/__mocks__/copy-to-clipboard.js +++ /dev/null @@ -1,6 +0,0 @@ -function copy(str, options = {}) { - copy.lastStr = str; - copy.lastOptions = options; -} - -export default copy; diff --git a/tests/__mocks__/copy-to-clipboard.ts b/tests/__mocks__/copy-to-clipboard.ts new file mode 100644 index 0000000000..7edb07b278 --- /dev/null +++ b/tests/__mocks__/copy-to-clipboard.ts @@ -0,0 +1,9 @@ +const copy: ((str?: string, options?: object) => void) & { + lastStr?: string; + lastOptions?: object; +} = (str: string, options = {}) => { + copy.lastStr = str; + copy.lastOptions = options; +}; + +export default copy; diff --git a/tests/__mocks__/rc-trigger.js b/tests/__mocks__/rc-trigger.tsx similarity index 57% rename from tests/__mocks__/rc-trigger.js rename to tests/__mocks__/rc-trigger.tsx index 813ac43067..88e9933fd8 100644 --- a/tests/__mocks__/rc-trigger.js +++ b/tests/__mocks__/rc-trigger.tsx @@ -1,9 +1,12 @@ import * as React from 'react'; import Trigger from 'rc-trigger/lib/mock'; +import type { TriggerProps } from 'rc-trigger'; import { TriggerMockContext } from '../shared/demoTestContext'; -export default React.forwardRef((props, ref) => { +const ForwardTrigger = React.forwardRef((props, ref) => { const mergedPopupVisible = React.useContext(TriggerMockContext) ?? props.popupVisible; - global.triggerProps = props; - return ; + (global as any).triggerProps = props; + return ; }); + +export default ForwardTrigger; diff --git a/tests/__mocks__/rc-util/lib/Portal.js b/tests/__mocks__/rc-util/lib/Portal.ts similarity index 71% rename from tests/__mocks__/rc-util/lib/Portal.js rename to tests/__mocks__/rc-util/lib/Portal.ts index c9d696b485..aeda831a67 100644 --- a/tests/__mocks__/rc-util/lib/Portal.js +++ b/tests/__mocks__/rc-util/lib/Portal.ts @@ -1,6 +1,8 @@ import React from 'react'; -export default class Portal extends React.Component { +class Portal extends React.Component<{ children?: React.ReactNode }> { + container: boolean; + componentDidMount() { this.createContainer(); } @@ -18,3 +20,5 @@ export default class Portal extends React.Component { return null; } } + +export default Portal; diff --git a/tests/__mocks__/rc-virtual-list.js b/tests/__mocks__/rc-virtual-list.ts similarity index 100% rename from tests/__mocks__/rc-virtual-list.js rename to tests/__mocks__/rc-virtual-list.ts