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

327
Views
"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
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!