Updating nodejs version from 14.x to 16.x results in Jest test cases failure

Viewed 50

I am trying to update nodeversion for the aws lambda from 14.x to 16.x, in doing so i am trying to update nodejs for the entire project in .node-version.

The test cases and application code is not written by me.

Before update the test cases were running fine however now the test cases are failing, can anyone help me on how to troubleshoot

here is the test case

import { Chance } from 'chance'
import axios from 'axios'

const chance = new Chance.Chance()

describe('ApiHeartbeatBookUpdatePreconditionDriver', () => {
  const driver = new ApiHeartbeatBookUpdatePreconditionDriver({
    httpConfig: {
      hostname: chance.string(),
      path: chance.string(),
      headers: {
        [chance.string()]: chance.string(),
      },
      data: {
        [chance.string()]: chance.string(),
      },
      book: chance.string(),
    },
  })
  describe('fullfill', () => {
    describe('When everything is ok', () => {
      test('The method should complete expectedly', async () => {
        jest.spyOn(axios, 'request').mockResolvedValueOnce({
          data: {
            upload_url: {
              whole_book: chance.string(),
              part_book: chance.string(),
            },
          },
        })
        jest.spyOn(axios, 'put').mockResolvedValueOnce({})
        expect(driver.fullfill(chance.string())).resolves.toBeUndefined()
      })
    })
  })
})

Here is the error

/Users/jatinmehrotra/Desktop/classmethod/Clients/xxxxx/xxxxxxx/node_modules/jest-jasmine2/node_modules/expect/build/index.js:134
  const err = new JestAssertionError();
              ^

JestAssertionError: expect(received).resolves.toBeUndefined()



  Received promise rejected instead of resolved
   Rejected to value: [Error: ENOENT: no such file or directory, open       '/opt/nodejs/node_modules/books/6enRV)AnZDa]g6qcp_diff.sdb']

Update:- The versions of library are as follows

"jest": "^26.2.2",
"jest-extended": "^0.11.5"
"ts-jest": "^26.1.4",

After attahcing debugger, to the test case where it fails i am seeing an usual error where test module is not able to find jest module even though it is present under node-module directory

error message from debugger

node:internal/modules/cjs/loader:959
  throw err;
  ^

Error: Cannot find module '/Users/jatinmehrotra/Desktop/classmethod/Clients/xxxxx/node_modules/.bin/jest'

code: 'MODULE_NOT_FOUND',
  requireStack: []
0 Answers
Related