From dd8f3714edf8f3094a207f7b394b8e830b8c9f89 Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Mon, 28 Jul 2025 17:20:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8D=E5=BA=94=E8=AF=A5je?= =?UTF-8?q?st=20console=E5=AF=BC=E8=87=B4=E7=9A=84ci=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/ECS/Core/EventSystem.test.ts | 8 ++++++++ tests/ECS/Scene.test.ts | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/tests/ECS/Core/EventSystem.test.ts b/tests/ECS/Core/EventSystem.test.ts index 9087d489..94daf56b 100644 --- a/tests/ECS/Core/EventSystem.test.ts +++ b/tests/ECS/Core/EventSystem.test.ts @@ -306,6 +306,8 @@ describe('EventSystem - 事件系统测试', () => { }); test('异步事件处理中的错误应该被正确处理', async () => { + const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + let successHandlerCalled = false; eventSystem.on('error:event', async () => { @@ -321,6 +323,8 @@ describe('EventSystem - 事件系统测试', () => { // 成功的处理器应该被调用 expect(successHandlerCalled).toBe(true); + + consoleSpy.mockRestore(); }); }); @@ -487,6 +491,8 @@ describe('EventSystem - 事件系统测试', () => { describe('错误处理', () => { test('监听器中的错误不应该影响其他监听器', () => { + const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + let successHandlerCalled = false; eventSystem.on('error:event', () => { @@ -504,6 +510,8 @@ describe('EventSystem - 事件系统测试', () => { // 成功的处理器应该被调用 expect(successHandlerCalled).toBe(true); + + consoleSpy.mockRestore(); }); test('应该能够处理监听器注册和移除中的边界情况', () => { diff --git a/tests/ECS/Scene.test.ts b/tests/ECS/Scene.test.ts index a7ef7e0c..918af2e8 100644 --- a/tests/ECS/Scene.test.ts +++ b/tests/ECS/Scene.test.ts @@ -507,6 +507,8 @@ describe('Scene - 场景管理系统测试', () => { }); test('系统处理过程中的异常应该被正确处理', () => { + const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + class ErrorSystem extends EntitySystem { constructor() { super(Matcher.empty().all(PositionComponent)); @@ -527,6 +529,8 @@ describe('Scene - 场景管理系统测试', () => { expect(() => { scene.update(); }).not.toThrow(); + + consoleSpy.mockRestore(); }); test('空场景的更新应该安全', () => {