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"]
}