javascriptnode.jsjestjsserverless-frameworkmiddy

TypeError: callback is not a function at terminate (node_modules/middy/src/middy.js:152:16)


My test is failing whenever i used middy, but when i remove it, my test succeed. the error that im encountering is "TypeError: callback is not a function at terminate (C:\cico\node_modules\middy\src\middy.js:152:16)"

I'm stuck and I need help.

command: yarn run jest

Heres my code:

test files:

describe('Partners', () => {
  describe('GET /partners', () => {
    test('should return partner list.', async () => {
     
      const result = await getPartner();

      const body = JSON.parse(result.body);

      expect(result.statusCode).toBe(httpStatus.OK);
      expect(body.data.length).toBe(1);
    });
  });
});

handler:

exports.getPartner = middy(async (event) => {
    // logic from db calling data 
});

middy:

module.exports = (fn) => {
  return middy(fn).use(jsonBodyParser()).use(httpEventNormalizer());
};

Solution

  • solved: use middy/core instead of middy itself. yarn add / npm i @middy/core instead of npm/yarn middy

    for more info -> https://middy.js.org/docs/category/intro-to-middy