diff --git a/src/core/nodeOps.test.ts b/src/core/nodeOps.test.ts index 248c9f445..16f993beb 100644 --- a/src/core/nodeOps.test.ts +++ b/src/core/nodeOps.test.ts @@ -129,6 +129,13 @@ describe('nodeOps', () => { it('throws an error if tag does not exist in catalogue', () => { expect(() => { nodeOps.createElement('THIS_TAG_DOES_NOT_EXIST', undefined, undefined, {}) }).toThrow() }) + + it('does not throw an error if `props` is `null`', () => { + expect(() => { nodeOps.createElement('TresPerspectiveCamera', undefined, undefined, null) }).not.toThrow() + expect(() => { nodeOps.createElement('TresMesh', undefined, undefined, null) }).not.toThrow() + expect(() => { nodeOps.createElement('TresBoxGeometry', undefined, undefined, null) }).not.toThrow() + expect(() => { nodeOps.createElement('TresMeshNormalMaterial', undefined, undefined, null) }).not.toThrow() + }) }) describe('insert', () => { diff --git a/src/core/nodeOps.ts b/src/core/nodeOps.ts index fb46fd2ff..ce104570d 100644 --- a/src/core/nodeOps.ts +++ b/src/core/nodeOps.ts @@ -30,7 +30,9 @@ const supportedPointerEvents = [ export const nodeOps: (context: TresContext) => RendererOptions = (context) => { const scene = context.scene.value - function createElement(tag: string, _isSVG: undefined, _anchor: any, props: Partial> = {}): TresObject | null { + function createElement(tag: string, _isSVG: undefined, _anchor: any, props: Partial> | null): TresObject | null { + if (!props) { props = {} } + if (!props.args) { props.args = [] }