From f8cae08bd96a760b120dcf60322abef30956d22a Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Thu, 10 Sep 2026 18:48:57 +0800 Subject: [PATCH] test(03-08): cover nullish event registrations - Exercise all eight registration functions with null and undefined\n- Assert resolved void results and unchanged fixture state --- .../data-state/src/event/event.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages-user/data-state/src/event/event.test.ts b/packages-user/data-state/src/event/event.test.ts index e5dedfa..21f48b7 100644 --- a/packages-user/data-state/src/event/event.test.ts +++ b/packages-user/data-state/src/event/event.test.ts @@ -235,6 +235,26 @@ describe('event built-ins', () => { expect(fixture.layer.getBlock(0, 0)).toBe(1); }); + // 验证八个真实注册 built-in 对 null 和 undefined 都安全返回且不改变状态 + it('safely resolves nullish parameters through every registered built-in', async () => { + const registrations = createEventBuiltinRegistrations(); + const expectedMap = [1, 1, 1, 1]; + const expectedHero = { x: 0, y: 0 }; + + for (const registration of registrations) { + for (const param of [null, undefined]) { + const fixture = createFixture(); + await expect( + invokeBuiltin(registration, param, fixture.env) + ).resolves.toBeUndefined(); + expect([...fixture.layer.getMapData()]).toEqual(expectedMap); + expect(fixture.state.hero.location.x).toBe(expectedHero.x); + expect(fixture.state.hero.location.y).toBe(expectedHero.y); + expect([...fixture.layer.iterateDynamicTiles()]).toHaveLength(0); + } + } + }); + // 验证缺失地图、勇士和事件 id 时所有函数都安全返回 it('safely skips missing targets and event ids', async () => { const fixture = createFixture();