|
@@ -1,5 +1,5 @@
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
-import { render, screen, waitFor } from '@testing-library/react';
|
|
|
|
|
|
|
+import { render, screen, waitFor, act } from '@testing-library/react';
|
|
|
import userEvent from '@testing-library/user-event';
|
|
import userEvent from '@testing-library/user-event';
|
|
|
import '@testing-library/jest-dom';
|
|
import '@testing-library/jest-dom';
|
|
|
import { TestWrapper } from '~/utils/client/test-render';
|
|
import { TestWrapper } from '~/utils/client/test-render';
|
|
@@ -139,9 +139,11 @@ describe('UsersPage Component', () => {
|
|
|
|
|
|
|
|
// 在搜索框中输入关键词 - 使用paste来避免防抖中间状态
|
|
// 在搜索框中输入关键词 - 使用paste来避免防抖中间状态
|
|
|
const searchInput = screen.getByPlaceholderText('搜索用户名、昵称或邮箱...');
|
|
const searchInput = screen.getByPlaceholderText('搜索用户名、昵称或邮箱...');
|
|
|
- await user.clear(searchInput);
|
|
|
|
|
- await user.click(searchInput);
|
|
|
|
|
- await user.paste('admin');
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await user.clear(searchInput);
|
|
|
|
|
+ await user.click(searchInput);
|
|
|
|
|
+ await user.paste('admin');
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// 等待防抖完成(300ms + 缓冲时间)
|
|
// 等待防抖完成(300ms + 缓冲时间)
|
|
|
await new Promise(resolve => setTimeout(resolve, 400));
|
|
await new Promise(resolve => setTimeout(resolve, 400));
|
|
@@ -637,9 +639,11 @@ describe('UsersPage Component', () => {
|
|
|
|
|
|
|
|
// 搜索不存在的用户
|
|
// 搜索不存在的用户
|
|
|
const searchInput = screen.getByPlaceholderText('搜索用户名、昵称或邮箱...');
|
|
const searchInput = screen.getByPlaceholderText('搜索用户名、昵称或邮箱...');
|
|
|
- await user.clear(searchInput);
|
|
|
|
|
- await user.click(searchInput);
|
|
|
|
|
- await user.paste('nonexistent');
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await user.clear(searchInput);
|
|
|
|
|
+ await user.click(searchInput);
|
|
|
|
|
+ await user.paste('nonexistent');
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// 等待防抖完成
|
|
// 等待防抖完成
|
|
|
await new Promise(resolve => setTimeout(resolve, 400));
|
|
await new Promise(resolve => setTimeout(resolve, 400));
|