diff --git a/tests/shared/imageTest.tsx b/tests/shared/imageTest.tsx index 009a4adbc6..af1a25e995 100644 --- a/tests/shared/imageTest.tsx +++ b/tests/shared/imageTest.tsx @@ -1,13 +1,13 @@ import path from 'path'; import React from 'react'; // Reference: https://github.com/ant-design/ant-design/pull/24003#discussion_r427267386 -// eslint-disable-next-line import/no-unresolved import { createCache, extractStyle, StyleProvider } from '@ant-design/cssinjs'; import dayjs from 'dayjs'; import fse from 'fs-extra'; import { globSync } from 'glob'; import { JSDOM } from 'jsdom'; import MockDate from 'mockdate'; +import type { HTTPRequest } from 'puppeteer'; import ReactDOMServer from 'react-dom/server'; import { App, ConfigProvider, theme } from '../../components'; @@ -72,7 +72,7 @@ export default function imageTest( unobserve() {}, disconnect() {}, }; - } as any; + } as unknown as typeof ResizeObserver; // Fake promise not called global.fetch = function mockFetch() { @@ -87,15 +87,14 @@ export default function imageTest( return this; }, }; - } as any; + } as unknown as typeof fetch; // Fake matchMedia - win.matchMedia = () => - ({ - matches: false, - addListener: jest.fn(), - removeListener: jest.fn(), - }) as any; + win.matchMedia = (() => ({ + matches: false, + addListener: jest.fn(), + removeListener: jest.fn(), + })) as unknown as typeof matchMedia; // Fill window fillWindowEnv(win); @@ -112,7 +111,7 @@ export default function imageTest( it(name, async () => { await page.setViewport({ width: 800, height: 600 }); - const onRequestHandle = (request: any) => { + const onRequestHandle = (request: HTTPRequest) => { if (['image'].includes(request.resourceType())) { request.abort(); } else { @@ -178,20 +177,17 @@ export default function imageTest( } await page.evaluate( - (innerHTML, ssrStyle, triggerClassName) => { - document.querySelector('#root')!.innerHTML = innerHTML; - - const head = document.querySelector('head')!; + (innerHTML: string, ssrStyle: string, triggerClassName?: string) => { + document.querySelector('#root')!.innerHTML = innerHTML; + const head = document.querySelector('head')!; head.innerHTML += ssrStyle; - // Inject open trigger with block style if (triggerClassName) { - document.querySelectorAll(`.${triggerClassName}`).forEach((node) => { + document.querySelectorAll(`.${triggerClassName}`).forEach((node) => { const blockStart = document.createElement('div'); const blockEnd = document.createElement('div'); - - node.parentNode!.insertBefore(blockStart, node); - node.parentNode!.insertBefore(blockEnd, node.nextSibling); + node.parentNode?.insertBefore(blockStart, node); + node.parentNode?.insertBefore(blockEnd, node.nextSibling); }); } },