【发布时间】:2019-07-12 08:10:13
【问题描述】:
在我的 nodejs lambda 函数中,我使用 AWSXray 来简单地捕获该函数进行的 https 调用。
const AWSXRay = require("aws-xray-sdk-core");
AWSXRay.captureHTTPsGlobal(require("https"));
在我的单元测试中,我如何模拟这个?
我试过用 sinon 模拟它:
before(async () =>
await sandbox.stub(AWSXRay, 'captureHTTPsGlobal').returns({})
);
after(async () => {
await sandbox.restore();
});
在测试中出现错误:
OperationalError: Failed to get the current sub/segment from the context.
at Object.contextMissingRuntimeError [as contextMissing]
【问题讨论】:
标签: node.js unit-testing aws-lambda sinon aws-xray