【发布时间】:2021-09-02 03:13:13
【问题描述】:
我正在尝试存根 aws-sdk/client-sqs 调用。我对 aws 和存根都是新手,我在文档中找不到太多与使用 mocha/chai 存根有关的内容
我的文件
import { SQSClient, ReceiveMessageCommand, DeleteMessageCommand } from '@aws-sdk/client-sqs'
const sqsClient = new SQSClient()
const params = {
AttributeNames: ['SentTimestamp'],
MaxNumberOfMessages: 10,
QueueUrl: paymentsUrl,
//....more params
}
const getPolledMessages = async sqsClient => {
const data = await sqsClient.send(new ReceiveMessageCommand(params))
//....continue to do stuff with the data
}
我的测试如下。我从这个test 大量借用了@aws-sdk/client-ses 的存根
import { ReceiveMessageCommand, SQSClient } from '@aws-sdk/client-sqs'
import { expect } from 'chai'
describe('mock sqs', () => {
let stub;
before(() => {
stub = sinon.stub(SQSClient.prototype, 'ReceiveMessageCommand')
})
after(() => stub.restore())
it('can send', async () => {
await SQSClient.send(new ReceiveMessageCommand(params))
expect(stub.calledOnce).to.be.true
})
})
目前出现以下错误
TypeError: Cannot stub non-existent property ReceiveMessageCommand
at Function.stub (node_modules/sinon/lib/sinon/stub.js:73:15)
at Sandbox.stub (node_modules/sinon/lib/sinon/sandbox.js:333:37)
【问题讨论】:
标签: javascript mocha.js chai sinon aws-sdk-js