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

87
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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