打字稿存根AWS开发工具包承诺

时间:2019-01-09 18:00:07

标签: typescript mocha aws-sdk sinon stub

我有这样的测试代码:

const ddb = new AWS.DynamoDB();
const q = sandbox.stub(ddb, "putItem");
const out: PromiseResult<PutItemOutput, AWSError> = { Attributes: {}, $response: null };
const queryParam = {
    TableName: "TEST",
    Item: {id: S: "123" },
    ConditionExpression: "attribute_not_exists(modified) OR modified <= :m",
    ExpressionAttributeValues: {
        ":m": {S: "2019-01-01"}
    }
};
q.withArgs(queryParam).returns({
    promise: () => (Promise.resolve(out))
});

但是我有一个错误: error TS2322: Type 'null' is not assignable to type 'Response<PutItemOutput, AWSError>'error TS2345: Argument of type '{ promise: () => Promise<PromiseResult<PutItemOutput, AWSError>>; }' is not assignable to parameter of type 'Request<PutItemOutput, AWSError>'

我的代码有什么问题?如何解决?

0 个答案:

没有答案