Skip to content

Commit

Permalink
chore(tests): add array attach case
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Oct 26, 2023
1 parent e5291a0 commit 4a60168
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions packages/fiber/tests/renderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,51 @@ describe('renderer', () => {
expect(scene.children).toStrictEqual(mixedArray)
})

it('can swap 4 array primitives via attach', async () => {
const a = new THREE.Group()
const b = new THREE.Group()
const c = new THREE.Group()
const d = new THREE.Group()
const array = [a, b, c, d]

const Test = ({ array }: { array: THREE.Group[] }) => (
<>
{array.map((group, i) => (
<primitive key={i} attach={`userData-objects-${i}`} object={group} />
))}
</>
)

const store = await act(async () => root.render(<Test array={array} />))
const state = store.getState()

expect(state.scene.children.length).toBe(0)
expect(state.scene.userData.objects[0]).toBe(a)
expect(state.scene.userData.objects[1]).toBe(b)
expect(state.scene.userData.objects[2]).toBe(c)
expect(state.scene.userData.objects[3]).toBe(d)

const reversedArray = [...array.reverse()]

await act(async () => root.render(<Test array={reversedArray} />))

expect(state.scene.children.length).toBe(0)
expect(state.scene.userData.objects[0]).toBe(d)
expect(state.scene.userData.objects[1]).toBe(c)
expect(state.scene.userData.objects[2]).toBe(b)
expect(state.scene.userData.objects[3]).toBe(a)

const mixedArray = [b, a, d, c]

await act(async () => root.render(<Test array={mixedArray} />))

expect(state.scene.children.length).toBe(0)
expect(state.scene.userData.objects[0]).toBe(b)
expect(state.scene.userData.objects[1]).toBe(a)
expect(state.scene.userData.objects[2]).toBe(d)
expect(state.scene.userData.objects[3]).toBe(c)
})

it('should gracefully handle text', async () => {
const warn = console.warn
console.warn = jest.fn()
Expand Down

0 comments on commit 4a60168

Please sign in to comment.