admin管理员组

文章数量:1336193

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
  ],
};

本文标签: javascriptJest unit tests are failing after jest upgrade to 2970 from 2706Stack Overflow