【问题标题】:TypeError: callback is not a function at terminate (node_modules/middy/src/middy.js:152:16)TypeError:回调不是终止时的函数(node_modules/middy/src/middy.js:152:16)
【发布时间】:2022-10-16 11:50:11
【问题描述】:

每当我使用 middy 时,我的测试都失败了,但是当我删除它时,我的测试成功了。我遇到的错误是“TypeError:callback is not a function at terminate (C:\cico\node_modules\middy\src\middy.js:152:16)”

我被困住了,我需要帮助。

命令:yarn run jest

这是我的代码:

测试文件:

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);
    });
  });
});

处理程序:

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

水手:

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

【问题讨论】:

    标签: javascript node.js jestjs serverless-framework middy


    【解决方案1】:

    已解决:使用 middy/core 而不是 middy 本身。 yarn add / npm i @middy/core 而不是 npm/yarn middy

    欲了解更多信息-> https://middy.js.org/docs/category/intro-to-middy

    【讨论】:

      猜你喜欢
      • 2020-07-17
      • 2018-01-22
      • 2018-06-05
      • 2017-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-25
      相关资源
      最近更新 更多