Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useTexture() breaks test-renderer unit tests #3077

Open
matehegedus opened this issue Oct 30, 2023 · 0 comments
Open

useTexture() breaks test-renderer unit tests #3077

matehegedus opened this issue Oct 30, 2023 · 0 comments

Comments

@matehegedus
Copy link

Hi, during unit testing I just found out that when I use useTexture(), it completely breaks the tree in the test results (thus all the test cases fail obviously...)

steps to reproduce:

Cube.jsx:

import React, {  useMemo } from "react";
import * as THREE from "../../modules/three.module";

import metalColorPic from "../../assets/metal/greenMetalRustDiff.jpg";
import metalAOPic from "../../assets/metal/greenMetalRustAO.jpg";
import metalNorPic from "../../assets/metal/greenMetalRustNorGL.jpg";
import metalRoughPic from "../../assets/metal/greenMetalRustRough.jpg";
import { useTexture } from "@react-three/drei";

const Cube = () => {
  const [colorMap, aoMap, normMap, roughMap] = useTexture([
    metalColorPic,
    metalAOPic,
    metalNorPic,
    metalRoughPic,
  ]);

  const material = useMemo(() => {
    return new THREE.MeshPhysicalMaterial({
      side: THREE.DoubleSide,
      map: colorMap,
      aoMap,
      normalMap: normMap,
      roughnessMap: roughMap,
      metalness: 0.8,
      roughness: 0.4,
    });
  }, [colorMap, aoMap, normMap, roughMap]);

  return (
    <group name="cubeContainer">
      <mesh material={material}>
        <boxGeometry />
      </mesh>
    </group>
  );
};

export default Cube;

renderer.test.js:

test("Test cubes rendered", async () => {
  const renderer = await ReactThreeTestRenderer.create(<Cube />);

  await new Promise((r) => setTimeout(r, 3000));

  const cubeContainer = renderer.scene.children[0];

  console.log("tree", renderer.toTree());
  console.log("container", cubeContainer);
}, 10000);

Result:
image

If I remove useTexture, result:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant