From 6b13e884dafd2347ad1cd554a36233045a52cb10 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 9 Jan 2024 22:27:25 -0500 Subject: [PATCH] fix(render): don't pass certain Text props to setProps --- src/render/gameobject.test.tsx | 22 +++++++++++++++++++++- src/render/gameobject.ts | 10 ++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/render/gameobject.test.tsx b/src/render/gameobject.test.tsx index 044e6c5d..26073f54 100644 --- a/src/render/gameobject.test.tsx +++ b/src/render/gameobject.test.tsx @@ -2,7 +2,7 @@ import Phaser from 'phaser'; import type { JSX } from 'react'; import { Container, Text } from '..'; -import { createGameObject } from '.'; +import { createGameObject, setProps } from '.'; jest.mock('phaser', () => { const GameObject = jest.fn(); @@ -23,6 +23,10 @@ jest.mock('./container', () => ({ })), })); +jest.mock('./props', () => ({ + setProps: jest.fn(), +})); + const scene = new Phaser.Scene(); function Component() { @@ -110,4 +114,20 @@ describe('Text', () => { props.style, ); }); + + it('does not pass certain Text props to setProps', () => { + const spy = jest.spyOn(console, 'error').mockImplementation(); + const props = { + children: [], + key: null, + ref: () => {}, + text: 'a', + style: {}, + }; + const element = ; + expect(createGameObject(element, scene, container)).toBeInstanceOf(Object); + expect(container.add).toBeCalledTimes(1); + expect(setProps).toBeCalledWith(expect.any(Object), {}, scene); + spy.mockRestore(); + }); }); diff --git a/src/render/gameobject.ts b/src/render/gameobject.ts index beef8bf8..5eed8eee 100644 --- a/src/render/gameobject.ts +++ b/src/render/gameobject.ts @@ -24,19 +24,13 @@ export function createGameObject( } // eslint-disable-next-line @typescript-eslint/no-unused-vars - const { children, key, ref, ...props } = element.props; + const { children, key, ref, style, text, ...props } = element.props; let gameObject: Phaser.GameObjects.GameObject; switch (element.type) { case Phaser.GameObjects.Text: - gameObject = new element.type( - scene, - props.x, - props.y, - props.text, - props.style, - ); + gameObject = new element.type(scene, props.x, props.y, text, style); break; default: