I am running some unit tests after a node version upgrade and jest version upgrade in package.json. It is erroring out with
TypeError: Cannot read properties of undefined (reading '_setAdapter')
The unit test attempts to mock a knex config.
import { mock as mockKnex, getTracker } from "mock-knex";
import { postgresConnectionPool } from "../../src/database/PostgresConnectionPool";
mockKnex(postgresConnectionPool); // This line is erroring out
describe("Test Suites", () => {
// test cases
})
However this is erroring out because a new object of mockKnex is not created. The error is TypeError: Cannot read properties of undefined (reading '_setAdapter')
// This code is from mock-knex public library
value: function mock(db) {
this._setAdapter(db); // It is failing on this line because the this object is undefined
return this._adapter.mock(db);
}
One of my questions is why is this happening ? Is it a jest issue or node issue ?
My Jest Config
module.exports = {
moduleFileExtensions: ["ts", "js"],
transform: {
".(ts)": "ts-jest",
},
testMatch: ["**/test/**/*.test.(ts|js)"],
testEnvironment: "node",
setupFiles: [
"<rootDir>/test/jestSetup.js", // mock required environment variables
],
};