dwyl / aws-sdk-mock

:rainbow: AWSomocks for Javascript/Node.js aws-sdk tested, documented & maintained. Contributions welcome!
Apache License 2.0
1.12k stars 110 forks source link

Attempted to wrap undefined property S3 as function #48

Open ghost opened 8 years ago

ghost commented 8 years ago

Here is my module:

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

Here is my test script:

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

I'm getting this error in the before hook:

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)

Thoughts?

andrepoleza commented 8 years ago

Weird, but I'm having the same issue as well.

andrepoleza commented 8 years ago

@hbarcelos-revmob I guess #47 might help you.