|
|
@@ -21,7 +21,7 @@ vi.mock('../../modules/users/user.service', () => ({
|
|
|
}))
|
|
|
}));
|
|
|
|
|
|
-// Mock 认证中间件
|
|
|
+// Mock 认证中间件 - 使用工厂函数确保每个测试有独立的mock实例
|
|
|
vi.mock('../../middleware/auth.middleware', () => ({
|
|
|
authMiddleware: vi.fn().mockImplementation((_c, next) => next())
|
|
|
}));
|
|
|
@@ -50,6 +50,10 @@ describe('Users API Integration Tests', () => {
|
|
|
beforeEach(async () => {
|
|
|
vi.clearAllMocks();
|
|
|
|
|
|
+ // 重置认证中间件mock
|
|
|
+ const { authMiddleware } = await import('../../middleware/auth.middleware');
|
|
|
+ vi.mocked(authMiddleware).mockImplementation((_c: any, next: any) => next());
|
|
|
+
|
|
|
// 动态导入用户路由
|
|
|
const userRoutes = await import('../users/index');
|
|
|
|