Skip to content

Commit

Permalink
chore(tests): harden recursive dispose case
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Nov 6, 2023
1 parent 3708229 commit 2ad846f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/fiber/tests/core/renderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,42 @@ describe('renderer', () => {
expect(ref.current!.userData.attach).toBe(attachedChild.current)
})

it('should recursively dispose of declarative children', async () => {
const parentDispose = jest.fn()
const childDispose = jest.fn()

await act(async () =>
root.render(
<mesh dispose={parentDispose}>
<mesh dispose={childDispose} />
</mesh>,
),
)
await act(async () => root.render(null))

expect(parentDispose).toBeCalledTimes(1)
expect(childDispose).toBeCalledTimes(1)
})

it('should not recursively dispose of flagged parent', async () => {
const parentDispose = jest.fn()
const childDispose = jest.fn()

await act(async () =>
root.render(
<group dispose={null}>
<mesh dispose={parentDispose}>
<mesh dispose={childDispose} />
</mesh>
</group>,
),
)
await act(async () => root.render(null))

expect(parentDispose).not.toBeCalled()
expect(childDispose).not.toBeCalled()
})

it('should not recursively dispose of attached primitives', async () => {
const meshDispose = jest.fn()
const primitiveDispose = jest.fn()
Expand Down

0 comments on commit 2ad846f

Please sign in to comment.