瀏覽代碼

Merge branch 'main' into feat/UseLoader

Alvaro Saburido 9 月之前
父節點
當前提交
a2cfb0b937
共有 2 個文件被更改,包括 10 次插入1 次删除
  1. 7 0
      src/core/nodeOps.test.ts
  2. 3 1
      src/core/nodeOps.ts

+ 7 - 0
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', () => {

+ 3 - 1
src/core/nodeOps.ts

@@ -30,7 +30,9 @@ const supportedPointerEvents = [
 export const nodeOps: (context: TresContext) => RendererOptions<TresObject, TresObject | null> = (context) => {
   const scene = context.scene.value
 
-  function createElement(tag: string, _isSVG: undefined, _anchor: any, props: Partial<WithMathProps<TresObject>> = {}): TresObject | null {
+  function createElement(tag: string, _isSVG: undefined, _anchor: any, props: Partial<WithMathProps<TresObject>> | null): TresObject | null {
+    if (!props) { props = {} }
+
     if (!props.args) {
       props.args = []
     }