diff --git a/package.json b/package.json index 2cf54b2..94d966b 100644 --- a/package.json +++ b/package.json @@ -26,12 +26,12 @@ }, "devDependencies": { "@testing-library/jest-dom": "^6.1.1", - "@testing-library/react": "^14.0.0", + "@testing-library/react": "^16.0.0", "@types/jest": "^29.5.3", "@types/react": "19.2.14", "@types/react-dom": "^19.2.3", - "@typescript-eslint/eslint-plugin": "^6.9.0", - "@typescript-eslint/parser": "^6.9.0", + "@typescript-eslint/eslint-plugin": "^8.0.0", + "@typescript-eslint/parser": "^8.0.0", "@umijs/test": "^4.6.32", "eslint": "^8.47.0", "eslint-config-prettier": "^10.1.8", @@ -41,10 +41,10 @@ "eslint-plugin-prettier": "^5.1.0", "eslint-plugin-react": "^7.33.2", "eslint-plugin-react-hooks": "^4.6.0", - "eslint-plugin-unused-imports": "^2.0.0", + "eslint-plugin-unused-imports": "^4.4.1", "jest": "^29.6.1", "mockjs": "^1.1.0", - "prettier": "^2.8.8", + "prettier": "^3.0.0", "prettier-plugin-organize-imports": "^3.2.2", "prettier-plugin-packagejson": "^2.4.3", "ts-jest": "^29.1.0", diff --git a/src/components/DropOption.test.tsx b/src/components/DropOption.test.tsx index d092f24..5c22c32 100644 --- a/src/components/DropOption.test.tsx +++ b/src/components/DropOption.test.tsx @@ -1,9 +1,9 @@ import { fireEvent, render, screen } from '@testing-library/react'; -import React from 'react'; import DropOption from './DropOption'; // Mock antd Dropdown to expose menu items for testing jest.mock('antd', () => { + const React = require('react'); return { Dropdown: ({ menu, children }: any) => React.createElement( @@ -31,10 +31,13 @@ jest.mock('antd', () => { }; }); -jest.mock('@ant-design/icons', () => ({ - BarsOutlined: () => React.createElement('span', null, 'Bars'), - DownOutlined: () => React.createElement('span', null, 'Down'), -})); +jest.mock('@ant-design/icons', () => { + const React = require('react'); + return { + BarsOutlined: () => React.createElement('span', null, 'Bars'), + DownOutlined: () => React.createElement('span', null, 'Down'), + }; +}); test('renders default trigger when no children provided', () => { render(); diff --git a/src/components/TopbarControls.tsx b/src/components/TopbarControls.tsx index f1d443e..d0a1e9c 100644 --- a/src/components/TopbarControls.tsx +++ b/src/components/TopbarControls.tsx @@ -74,9 +74,9 @@ export default function TopbarControls({ goProfile, onLogout }: Props) { const handleProfileClick = (key: string) => { if (key === 'profile') { - goProfile && goProfile(); + goProfile?.(); } else if (key === 'logout') { - onLogout && onLogout(); + onLogout?.(); } }; diff --git a/src/pages/sys/menu/components/SortModal.tsx b/src/pages/sys/menu/components/SortModal.tsx index 65e1021..95f4a3e 100644 --- a/src/pages/sys/menu/components/SortModal.tsx +++ b/src/pages/sys/menu/components/SortModal.tsx @@ -74,7 +74,7 @@ export default function SortModal({ open, menus, onCancel, onConfirm }: Props) { route: r.route || '/', sort: r.sort, children: r.children ? buildMenuTree(r.children) : undefined, - } as MenuItem), + }) as MenuItem, ); }; diff --git a/src/utils/request.test.ts b/src/utils/request.test.ts index cf9aa40..7c83a47 100644 --- a/src/utils/request.test.ts +++ b/src/utils/request.test.ts @@ -41,7 +41,7 @@ describe('api', () => { const err = new Error('net fail'); (global.fetch as jest.Mock).mockRejectedValue(err); const spy = jest.spyOn(message, 'error') as jest.SpyInstance; - spy.mockImplementation(() => ({} as any)); + spy.mockImplementation(() => ({}) as any); await expect(api('/x')).rejects.toThrow('net fail'); expect(spy).toBeCalledWith('net fail'); spy.mockRestore(); @@ -54,7 +54,7 @@ describe('api', () => { json: async () => ({}), }); const spy = jest.spyOn(message, 'error') as jest.SpyInstance; - spy.mockImplementation(() => ({} as any)); + spy.mockImplementation(() => ({}) as any); await expect(api('/x')).rejects.toThrow('Invalid API response format'); expect(spy).toBeCalledWith('Invalid API response format'); spy.mockRestore();