Sfoglia il codice sorgente

feat(core): fixed nodeOps remove test

Tino Koch 2 anni fa
parent
commit
2706f487aa
2 ha cambiato i file con 7 aggiunte e 11 eliminazioni
  1. 1 6
      src/core/nodeOps.ts
  2. 6 5
      src/core/nodeOpts.test.ts

+ 1 - 6
src/core/nodeOps.ts

@@ -127,12 +127,6 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
   remove(node) {
     if (!node) return
 
-    const parent = node.parentNode // TODO is there ever a case when this is true? which entity has a fn called removeChild?
-
-    if (parent) {
-      parent.removeChild(node)
-    }
-
     // remove is only called on the node being removed and not on child nodes.
 
     if (node.isObject3D) {
@@ -152,6 +146,7 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
     }
 
     node.removeFromParent?.()
+
     node.dispose?.() // TODO is dispose ever set?
   },
   patchProp(node, prop, _prevValue, nextValue) {

+ 6 - 5
src/core/nodeOpts.test.ts

@@ -108,15 +108,16 @@ describe('nodeOps', () => {
 
   it('remove: removes child from parent', async () => {
     // Setup
-    const parent: TresObject = new Scene()
-    const child: TresObject = new Mesh()
-    parent.children.push(child)
+    const scene = new Scene() as unknown as TresObject
+    const mesh = new Mesh() as unknown as TresObject
+
+    nodeOps.insert(mesh, scene)
 
     // Test
-    nodeOps.remove(child)
+    nodeOps.remove(mesh)
 
     // Assert
-    expect(!parent.children.includes(child))
+    expect(!scene.children.length)
   })
 
   it('patchProp should patch property of node', async () => {