首先,我不使用lambda,所以我認爲this thread不是同一個問題。用dwyl/aws-sdk-mock模擬AWS不起作用
我得到這個錯誤在before
鉤:
TypeError: Attempted to wrap undefined property S3 as function
at checkWrappedMethod (node_modules/aws-sdk-mock/node_modules/sinon/lib/sinon/util/core.js:78:29)
at Object.wrapMethod (node_modules/aws-sdk-mock/node_modules/sinon/lib/sinon/util/core.js:121:21)
at Object.stub (node_modules/aws-sdk-mock/node_modules/sinon/lib/sinon/stub.js:67:26)
at mockService (node_modules/aws-sdk-mock/index.js:67:27)
at Object.AWS.mock (node_modules/aws-sdk-mock/index.js:43:5)
at Context.<anonymous> (myModule.spec.js:14:9)
我從來沒有使用此模塊之前我也不有sinon.js很多經驗。
這裏是我的模塊:
var AWS = require('aws-sdk')
const https = require('https')
module.exports = function() {
var s3 = new AWS.S3({
httpOptions: {
agent: new https.Agent()
},
signatureVersion: 'v4'
})
return s3.getObject({Bucket: 'somebucket', Key: 'somekey'}).promise()
}
這裏是我的測試腳本:
const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
const AWS = require('aws-sdk-mock')
const myFunc = require('./myModule')
chai.use(chaiAsPromised)
const expect = chai.expect
chai.should()
describe('Get MMS API Key', function() {
before(function() {
AWS.mock('S3', 'getObject', function (params, callback) {
callback(null, 'dummy-data')
})
})
it('Should get dummy data', function() {
myFunc().should.eventually.equal('dummy-data')
})
after(function() {
AWS.restore('S3', 'getObject')
})
})
的思考?