From 2706f487aa4c2c2e447f45d7ed030f2a766ad593 Mon Sep 17 00:00:00 2001 From: Tino Koch Date: Thu, 6 Apr 2023 12:57:03 +0200 Subject: [PATCH] feat(core): fixed nodeOps remove test --- src/core/nodeOps.ts | 7 +------ src/core/nodeOpts.test.ts | 11 ++++++----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/core/nodeOps.ts b/src/core/nodeOps.ts index b7dc5ef4a..e63f322dc 100644 --- a/src/core/nodeOps.ts +++ b/src/core/nodeOps.ts @@ -127,12 +127,6 @@ export const nodeOps: RendererOptions = { 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 = { } node.removeFromParent?.() + node.dispose?.() // TODO is dispose ever set? }, patchProp(node, prop, _prevValue, nextValue) { diff --git a/src/core/nodeOpts.test.ts b/src/core/nodeOpts.test.ts index 75e9a4ba6..850e7e3af 100644 --- a/src/core/nodeOpts.test.ts +++ b/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 () => {