-
Hi, I'm trying to test a component created with gltfjsx. I use the My problem is that when I create the renderer and try to reach the renderer.scene.children value it returns me an empty array. I think it's because the I tried to test a basic mesh like the one below and also the manually copied useGLTF output from the Ground component and it seemed to work properly, but I don't think it's a good way to mock that object because it won't update automatically when I edit the gltf model in the future. Is there a way of testing the components based on gltf files or maybe it's not the right thing to test? Basic mesh I tested<mesh>
<boxBufferGeometry />
<MeshStandardMaterial />
</mesh> My Ground.tsx componentimport { useGLTF } from '@react-three/drei'
import React, { useRef } from 'react'
import * as THREE from 'three'
import { GroundGLTFResult, GroundProps } from './Ground.types'
const path = './GLTFModels/Ground.gltf'
const Ground: React.FC<GroundProps> = ({ color, ...props }: GroundProps) => {
const group = useRef<THREE.Group>()
const { nodes, materials } = useGLTF(path) as GroundGLTFResult
if (color) materials.GroundMaterial.color.set(color)
return (
<group ref={group} {...props} dispose={null}>
<group name="Scene">
<mesh
name="Ground"
castShadow
receiveShadow
geometry={nodes.Ground.geometry}
material={materials.GroundMaterial}
/>
</group>
</group>
)
}
export default Ground
useGLTF.preload(path) My Ground.test.tsximport ReactThreeTestRenderer from '@react-three/test-renderer'
import React, { Suspense } from 'react'
import Ground from './Ground'
test('Ground component should change its color to the one provided as prop', async () => {
const renderer = await ReactThreeTestRenderer.create(
<Suspense fallback={null}>
<Ground color="red" />
</Suspense>
)
const mesh = renderer.scene.children
// expect(mesh...
}) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
'./GLTFModels/Ground.gltf' can never work, that is a relative path, bundlers would not know what to do with that. think of it like this, your bundler is creating a distributable, it takes everything you reference and puts it into the /dist folder or bundles it together. your ground.gltf does not exist there, and you don't give it any clue that you need it. simply doing fetch('./model.gltf') does nothing, because './model.gltf' is just a string. three's loaders are using plain fetch, ergo your bundler is clueless, builds the app and when you load that file's missing.
|
Beta Was this translation helpful? Give feedback.
'./GLTFModels/Ground.gltf' can never work, that is a relative path, bundlers would not know what to do with that. think of it like this, your bundler is creating a distributable, it takes everything you reference and puts it into the /dist folder or bundles it together. your ground.gltf does not exist there, and you don't give it any clue that you need it. simply doing fetch('./model.gltf') does nothing, because './model.gltf' is just a string. three's loaders are using plain fetch, ergo your bundler is clueless, builds the app and when you load that file's missing.