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

326
Vistas
"SyntaxError: Cannot use import statement outside a module" error while testing a Nodejs project with Jest

So I'm working on a Nodejs project with expressjs and I'm trying to use Jest to test my apis. I've read about configuring Jest in the documentation, but I'm new to jest and it's a bit confusing. The error I'm getting :

SyntaxError: Cannot use import statement outside a module at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1796:14)

My test file:

const userController = require("../controllers/user.controller");
const router = require("../routes/user.routes");


//Testing login route
describe("POST /api/user/login", () => {
    describe("given a username and password", () => {
  
      test("should respond with a 200 status code", async () => {
        const response = await request(router).post("/login").send({
          username: "username",
          password: "password"
        })
        expect(response.statusCode).toBe(200)
      })
     })
  

  
  })
about 4 years ago · Juan Pablo Isaza
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