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

208
Views
Does jest redefine the Error global variable?

I have a very simple test:

    beforeAll(async () => {
      try {
        await db.connect();
      } catch(e: any) {
        expect(e).toBeInstanceOf(Error);
      }
    });

but it fail with this really strange message

    expect(received).toBeInstanceOf(expected)

    Expected constructor: Error
    Received constructor: Error

so I suspect the value of Error while running a jest test is redefined.

jest.config.js:

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
  preset:                 "ts-jest",
  testEnvironment:        "node",
  testPathIgnorePatterns: ["/node_modules/"]
};

partial package.json:

{
  "devDependencies": {
    "@types/jest": "28.1.3",
    "@types/node": "18.0.0",
    "jest": "28.1.1",
    "ts-jest": "28.0.5",
    "ts-node": "10.8.1",
    "typescript": "4.7.4",
  },
  "scripts": {
    "coverage": "jest --coverage",
    "test": "jest",
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "alwaysStrict": true,
    "esModuleInterop": true,
    "moduleResolution": "Node",
    "noImplicitAny": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "strict": true,
    "strictBindCallApply": true,
    "strictFunctionTypes": true,
    "strictNullChecks": true,
    "strictPropertyInitialization": true,
    "target": "ESNext"
  },
  "exclude": ["*.d.ts"],
  "include": ["*.ts", "test/*.ts"]
}
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!