fix(types): 修复 16 个 TypeScript 类型检查错误
- 修复 animations.test.tsx 中的 Variant 类型访问问题 - 清理 9 个测试文件中的未使用导入 - 使用可选链操作符处理可能为 undefined 的属性访问 - 修复 mock 组件缺少 displayName 的 ESLint 错误
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { describe, it, expect, jest, beforeAll } from '@jest/globals';
|
||||
import { describe, it, expect, jest } from '@jest/globals';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
|
||||
@@ -35,11 +35,13 @@ jest.mock('framer-motion', () => ({
|
||||
}));
|
||||
|
||||
jest.mock('next/link', () => {
|
||||
return ({ children, href, ...props }: any) => (
|
||||
const MockLink = ({ children, href, ...props }: any) => (
|
||||
<a href={href} {...props}>
|
||||
{children}
|
||||
</a>
|
||||
);
|
||||
MockLink.displayName = 'MockLink';
|
||||
return MockLink;
|
||||
});
|
||||
|
||||
jest.mock('lucide-react', () => ({
|
||||
|
||||
@@ -11,28 +11,13 @@ jest.mock('next/navigation', () => ({
|
||||
}));
|
||||
|
||||
jest.mock('next/link', () => {
|
||||
return ({ children, href }: { children: React.ReactNode; href: string }) => {
|
||||
const MockLink = ({ children, href }: { children: React.ReactNode; href: string }) => {
|
||||
return <a href={href}>{children}</a>;
|
||||
};
|
||||
MockLink.displayName = 'MockLink';
|
||||
return MockLink;
|
||||
});
|
||||
|
||||
const mockProduct = {
|
||||
id: 'test-product',
|
||||
title: '测试产品',
|
||||
category: '企业软件',
|
||||
description: '这是测试产品描述',
|
||||
overview: '这是测试产品概述',
|
||||
features: ['功能1', '功能2'],
|
||||
benefits: ['优势1', '优势2'],
|
||||
process: ['步骤1', '步骤2'],
|
||||
specs: ['规格1', '规格2'],
|
||||
pricing: {
|
||||
base: '¥10,000/年',
|
||||
standard: '¥30,000/年',
|
||||
enterprise: '定制',
|
||||
},
|
||||
};
|
||||
|
||||
jest.mock('@/lib/constants', () => ({
|
||||
PRODUCTS: [
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, beforeEach, jest } from '@jest/globals';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { ErrorBoundary } from './error-boundary';
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as React from 'react';
|
||||
import { describe, it, expect, jest, beforeEach } from '@jest/globals';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import '@testing-library/jest-dom';
|
||||
import { Input } from './input';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from '@jest/globals';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { render } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import {
|
||||
Skeleton,
|
||||
|
||||
@@ -34,8 +34,6 @@ jest.mock('framer-motion', () => ({
|
||||
AnimatePresence: ({ children }: { children: React.ReactNode }) => <>{children}</>,
|
||||
}));
|
||||
|
||||
const { RippleButton } = jest.requireActual('./ripple-button');
|
||||
|
||||
describe('RippleButton', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
SheetFooter,
|
||||
SheetTitle,
|
||||
SheetDescription,
|
||||
SheetClose,
|
||||
} from './sheet';
|
||||
|
||||
describe('Sheet', () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as React from 'react';
|
||||
import { describe, it, expect, jest, beforeEach } from '@jest/globals';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import '@testing-library/jest-dom';
|
||||
import { Textarea } from './textarea';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, beforeEach, jest } from '@jest/globals';
|
||||
import { renderHook, act } from '@testing-library/react';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { useFocusTrap } from './use-focus-trap';
|
||||
|
||||
describe('useFocusTrap', () => {
|
||||
|
||||
@@ -77,7 +77,7 @@ describe('Animation Variants', () => {
|
||||
|
||||
it('should have correct transition configuration', async () => {
|
||||
const { inkVariants } = await import('./animations');
|
||||
const transition = inkVariants.visible.transition as any;
|
||||
const transition = (inkVariants.visible as any)?.transition;
|
||||
expect(transition.duration).toBe(0.8);
|
||||
expect(transition.ease).toEqual([0.16, 1, 0.3, 1]);
|
||||
});
|
||||
@@ -102,7 +102,7 @@ describe('Animation Variants', () => {
|
||||
|
||||
it('should use spring animation', async () => {
|
||||
const { sealStampVariants } = await import('./animations');
|
||||
const transition = sealStampVariants.visible.transition as any;
|
||||
const transition = (sealStampVariants.visible as any)?.transition;
|
||||
expect(transition.type).toBe('spring');
|
||||
expect(transition.stiffness).toBe(300);
|
||||
expect(transition.damping).toBe(20);
|
||||
@@ -144,7 +144,7 @@ describe('Animation Variants', () => {
|
||||
describe('staggerContainerVariants', () => {
|
||||
it('should have staggerChildren configured', async () => {
|
||||
const { staggerContainerVariants } = await import('./animations');
|
||||
const transition = staggerContainerVariants.visible.transition as any;
|
||||
const transition = (staggerContainerVariants.visible as any)?.transition;
|
||||
expect(transition.staggerChildren).toBe(0.1);
|
||||
expect(transition.delayChildren).toBe(0.1);
|
||||
});
|
||||
@@ -412,7 +412,7 @@ describe('Animation Components', () => {
|
||||
const { GlitchText } = await import('./animations');
|
||||
render(<GlitchText text="Test" className="glitch-class" />);
|
||||
const testElements = screen.getAllByText('Test');
|
||||
const container = testElements[0].closest('.glitch-class');
|
||||
const container = testElements[0]?.closest('.glitch-class');
|
||||
expect(container).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user