Skip to content

Commit

Permalink
fix(render): don't pass certain Text props to setProps
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 10, 2024
1 parent 994828e commit 6b13e88
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
22 changes: 21 additions & 1 deletion src/render/gameobject.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -23,6 +23,10 @@ jest.mock('./container', () => ({
})),
}));

jest.mock('./props', () => ({
setProps: jest.fn(),
}));

const scene = new Phaser.Scene();

function Component() {
Expand Down Expand Up @@ -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 = <Text {...props} />;
expect(createGameObject(element, scene, container)).toBeInstanceOf(Object);
expect(container.add).toBeCalledTimes(1);
expect(setProps).toBeCalledWith(expect.any(Object), {}, scene);
spy.mockRestore();
});
});
10 changes: 2 additions & 8 deletions src/render/gameobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6b13e88

Please sign in to comment.