Skip to content

Commit

Permalink
feat(core): fixed nodeOps remove test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinoooo committed Apr 6, 2023
1 parent cae21b1 commit 2706f48
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
7 changes: 1 addition & 6 deletions src/core/nodeOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -152,6 +146,7 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
}

node.removeFromParent?.()

node.dispose?.() // TODO is dispose ever set?
},
patchProp(node, prop, _prevValue, nextValue) {
Expand Down
11 changes: 6 additions & 5 deletions src/core/nodeOpts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 2706f48

Please sign in to comment.