Skip to content

Commit 425b6bd

Browse files
chore(tests): use names in swap cases
1 parent 1cde392 commit 425b6bd

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

packages/fiber/tests/renderer.test.tsx

+18-23
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,13 @@ describe('renderer', () => {
410410

411411
it('can swap 4 array primitives', async () => {
412412
const a = new THREE.Group()
413+
a.name = 'a'
413414
const b = new THREE.Group()
415+
b.name = 'b'
414416
const c = new THREE.Group()
417+
c.name = 'c'
415418
const d = new THREE.Group()
419+
d.name = 'd'
416420

417421
const Test = ({ array }: { array: THREE.Group[] }) => (
418422
<>
@@ -426,15 +430,15 @@ describe('renderer', () => {
426430
const store = await act(async () => root.render(<Test array={array} />))
427431
const { scene } = store.getState()
428432

429-
expect(scene.children).toStrictEqual(array)
433+
expect(scene.children.map((o) => o.name)).toStrictEqual(array.map((o) => o.name))
430434

431435
const reversedArray = [d, c, b, a]
432436
await act(async () => root.render(<Test array={reversedArray} />))
433-
expect(scene.children).toStrictEqual(reversedArray)
437+
expect(scene.children.map((o) => o.name)).toStrictEqual(reversedArray.map((o) => o.name))
434438

435439
const mixedArray = [b, a, d, c]
436440
await act(async () => root.render(<Test array={mixedArray} />))
437-
expect(scene.children).toStrictEqual(mixedArray)
441+
expect(scene.children.map((o) => o.name)).toStrictEqual(mixedArray.map((o) => o.name))
438442
})
439443

440444
// TODO: fix this case, also see:
@@ -443,9 +447,13 @@ describe('renderer', () => {
443447
// https://github.com/pmndrs/react-three-fiber/issues/3143
444448
it.skip('can swap 4 array primitives via attach', async () => {
445449
const a = new THREE.Group()
450+
a.name = 'a'
446451
const b = new THREE.Group()
452+
b.name = 'b'
447453
const c = new THREE.Group()
454+
c.name = 'c'
448455
const d = new THREE.Group()
456+
d.name = 'c'
449457
const array = [a, b, c, d]
450458

451459
const Test = ({ array }: { array: THREE.Group[] }) => (
@@ -457,33 +465,20 @@ describe('renderer', () => {
457465
)
458466

459467
const store = await act(async () => root.render(<Test array={array} />))
460-
const state = store.getState()
468+
const { scene } = store.getState()
461469

462-
expect(state.scene.children.length).toBe(0)
463-
expect(state.scene.userData.objects[0]).toBe(a)
464-
expect(state.scene.userData.objects[1]).toBe(b)
465-
expect(state.scene.userData.objects[2]).toBe(c)
466-
expect(state.scene.userData.objects[3]).toBe(d)
470+
expect(scene.children.length).toBe(0)
471+
expect(scene.userData.objects.map((o: THREE.Object3D) => o.name)).toStrictEqual(array.map((o) => o.name))
467472

468473
const reversedArray = [...array.reverse()]
469-
470474
await act(async () => root.render(<Test array={reversedArray} />))
471-
472-
expect(state.scene.children.length).toBe(0)
473-
expect(state.scene.userData.objects[0]).toBe(d)
474-
expect(state.scene.userData.objects[1]).toBe(c)
475-
expect(state.scene.userData.objects[2]).toBe(b)
476-
expect(state.scene.userData.objects[3]).toBe(a)
475+
expect(scene.children.length).toBe(0)
476+
expect(scene.userData.objects.map((o: THREE.Object3D) => o.name)).toStrictEqual(reversedArray.map((o) => o.name))
477477

478478
const mixedArray = [b, a, d, c]
479-
480479
await act(async () => root.render(<Test array={mixedArray} />))
481-
482-
expect(state.scene.children.length).toBe(0)
483-
expect(state.scene.userData.objects[0]).toBe(b)
484-
expect(state.scene.userData.objects[1]).toBe(a)
485-
expect(state.scene.userData.objects[2]).toBe(d)
486-
expect(state.scene.userData.objects[3]).toBe(c)
480+
expect(scene.children.length).toBe(0)
481+
expect(scene.userData.objects.map((o: THREE.Object3D) => o.name)).toStrictEqual(mixedArray.map((o) => o.name))
487482
})
488483

489484
it('should gracefully handle text', async () => {

0 commit comments

Comments
 (0)