diff --git a/components/__tests__/util/domHook.js b/components/__tests__/util/domHook.ts similarity index 79% rename from components/__tests__/util/domHook.js rename to components/__tests__/util/domHook.ts index dddc3ffc27..26f4a0532f 100644 --- a/components/__tests__/util/domHook.js +++ b/components/__tests__/util/domHook.ts @@ -1,6 +1,10 @@ const __NULL__ = { notExist: true }; -export function spyElementPrototypes(Element, properties) { +type ElementType
= { + prototype: P; +}; + +export function spyElementPrototypes
(Element: ElementType
, properties: P) {
const propNames = Object.keys(properties);
const originDescriptors = {};
@@ -51,7 +55,16 @@ export function spyElementPrototypes(Element, properties) {
};
}
-export function spyElementPrototype(Element, propName, property) {
+type FunctionPropertyNames >(
+ Element: ElementType ,
+ propName: K,
+ property: P[K],
+) {
return spyElementPrototypes(Element, {
[propName]: property,
});
diff --git a/components/affix/__tests__/Affix.test.js b/components/affix/__tests__/Affix.test.tsx
similarity index 91%
rename from components/affix/__tests__/Affix.test.js
rename to components/affix/__tests__/Affix.test.tsx
index 78c81d5c6b..1c34b576ef 100644
--- a/components/affix/__tests__/Affix.test.js
+++ b/components/affix/__tests__/Affix.test.tsx
@@ -7,9 +7,17 @@ import { spyElementPrototype } from '../../__tests__/util/domHook';
import rtlTest from '../../../tests/shared/rtlTest';
import { sleep } from '../../../tests/utils';
-const events = {};
+const events: any = {};
+
+class AffixMounter extends React.Component<{
+ offsetBottom?: number;
+ offsetTop?: number;
+ onTestUpdatePosition?(): void;
+}> {
+ private container: HTMLDivElement;
+
+ private affix: Affix;
-class AffixMounter extends React.Component {
componentDidMount() {
this.container.addEventListener = jest.fn().mockImplementation((event, cb) => {
events[event] = cb;
@@ -47,7 +55,7 @@ describe('Affix Render', () => {
let wrapper;
let domMock;
- const classRect = {
+ const classRect: any = {
container: {
top: 0,
bottom: 100,
@@ -135,9 +143,9 @@ describe('Affix Render', () => {
describe('updatePosition when target changed', () => {
it('function change', () => {
document.body.innerHTML = '