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

139
Visualizações
Vite SVG Imports Break Jest Tests

I'm trying to use Jest and Vite together and they're not playing nice.

One of my components makes use of Vite's asset bundling feature where we can import an SVG like this:

import React from "react";
import mainLogo from "../../assets/main-logo.svg";

const MyComponent = () => {
  return (
       <div className="main-logo w-full">
        <img src={mainLogo} className="w-64" />
      </div>
  )
}

This works fine in Vite, but when I try to test this file with Jest I get the following complaint:

The Jest error

It looks like this is happening because Vite is correctly parsing the SVG when running the development server and doesn't need any extra loaders, whereas Jest doesn't know what to do here. I've tried using various transforms for SVG files, but none of them seem to work.

Anyone have an idea of how to solve this?

// jest.config.js

const config = {
  verbose: true,
  moduleNameMapper: { "\\.(css|scss|sass)$": "identity-obj-proxy" },
  setupFiles: ["./jest.setup.js"],
  testEnvironment: "jsdom",
};

module.exports = config;
//vite.config.js

import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [react()],
  root: "client",
  envDir: "./environment",
  build: {
    outDir: "../build",
  },
  server: {
    host: true,
    proxy: {
      "/api": {
        target: "http://localhost:3001",
        changeOrigin: true,
        secure: false,
      },
    },
  },
});
about 4 years ago · Santiago Trujillo
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