Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

531
Visualizações
Mapbox Unit Testing - Failed to initialize WebGL

I'm currently using Mapbox for a React application and I'm trying to perform unit testing but it doesn't seem to work. I've set the Mapbox testMode to true and it still gives me an error saying:

Error: Failed to initialize WebGL.
at new Map (C:\Users\...\node_modules\mapbox-gl\dist\mapbox-gl.js:35:427889)

The following snippet is how we generate the mapbox component which also receives a test variable to set the testMode.

const MapBox = (props: MapBoxProps) => {
  const { floorPlan, isTest } = props;
  const { width } = useWindowDimensions();
  const mapContainer = useRef(null);
  const map = useRef(null);
  const [lng, setLng] = useState(48);
  const [lat, setLat] = useState(25);
  const [zoom, setZoom] = useState(1.8);

  const createMapbox = () => {
    if (!isTest) {
      mapboxgl.accessToken = appConfig.MAPBOX_TOKEN;
    }
    const mb = new mapboxgl.Map({
      attributionControl: false,
      container: mapContainer.current,
      testMode: isTest,
      style: {
        version: 8,
        sources: {},
        layers: [
          {
            id: "background",
            type: "background",
            paint: {
              "background-color": "white",
            },
          },
        ],
      },
      center: [lng, lat],
      zoom: zoom,
      maxZoom: 6,
      dragRotate: false,
    });
    mb.addControl(new mapboxgl.NavigationControl({ showCompass: false }));
    return mb;
  };
  return <div
        data-cr="mapbox-container"
        ref={mapContainer}
      />;
}

And the code for testing our CustomMapBox component is as follows:

const renderMapBox = () => {
  return render(<CustomMapBox floorPlan={mockedFloorPlan} isTest={true} />);
};

describe("MapBox", () => {
  it("renders without error and two floors", () => {
    renderMapBox();
  });
}

I've tried to:

  • Change versions
  • Change jest configurations
  • Set mapbox testMode to true

And nothing seems to work.

Versions:

"mapbox-gl": "^2.8.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"ts-jest": "^27.0.7",
"jest": "^27.3.1",

I'd really appreciate if someone could help me. Best regards, Daniel

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda