Skip to content

Commit

Permalink
chore(tests): harden useLoader case w/gltf specifics
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Nov 28, 2023
1 parent 3ccb839 commit 803ee2c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/fiber/tests/core/hooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,23 @@ describe('hooks', () => {
})

it('can handle useLoader hook', async () => {
let gltf!: Stdlib.GLTF & ObjectMap

const MockMesh = new THREE.Mesh()
MockMesh.name = 'Scene'

jest.spyOn(Stdlib, 'GLTFLoader').mockImplementation(
() =>
({
load: jest.fn().mockImplementation((_url, onLoad) => {
onLoad({ scene: MockMesh, nodes: { Scene: MockMesh } })
onLoad({ scene: MockMesh })
}),
} as unknown as Stdlib.GLTFLoader),
)

const Component = () => {
const { scene, nodes } = useLoader(Stdlib.GLTFLoader, '/suzanne.glb')
return <primitive object={scene} />
gltf = useLoader(Stdlib.GLTFLoader, '/suzanne.glb')
return <primitive object={gltf.scene} />
}

let scene: THREE.Scene = null!
Expand All @@ -122,6 +126,8 @@ describe('hooks', () => {
await waitFor(() => expect(scene.children[0]).toBeDefined())

expect(scene.children[0]).toBe(MockMesh)
expect(gltf.scene).toBe(MockMesh)
expect(gltf.nodes.Scene).toBe(MockMesh)
})

it('can handle useLoader hook with an array of strings', async () => {
Expand Down

0 comments on commit 803ee2c

Please sign in to comment.