Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

88
Vistas
VS Code imports using the require syntax in React test cases

Little lately, I have found that my react project in the VS Code IDE is using require syntax in the test cases when I'm doing auto import from the suggestions. Could anyone please help?

I'm using React testing library and here's how it looks like.

const { render } = require("@testing-library/react");
const { default: Home } = require("../Home");

describe("Home", () => {
  it("should render Search page", () => {
    const { container } = render(<Home />);
  });
});

I have a jsconfig.json file as follows

{
  "compilerOptions": {
    "baseUrl": "src"
  },
  "include": [
    "src"
  ],
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

From the new feature CommonJS auto imports, we know:

If VS Code detects that you are working in a CommonJS style JavaScript module, auto imports will now use require instead of import.

You can set compilerOptions.module to es2015 for jsconfig.json. So that the js file will be detected as ESM, auto imports will use import instead of require.

jsconfig.json:

{
  "compilerOptions": {
    "module": "es2015"
  },
}
// auto imports use `import` keyword.
import { render } from 'react-dom';

describe('Home', () => {
  it('should render Search page', () => {
    render
  });
});

For more info about when VS code uses require, see shouldUseRequire function.

P.S If it does not work, try to reload the window of VS code after adding this configuration.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda