Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!