aws-sdk-mock icon indicating copy to clipboard operation
aws-sdk-mock copied to clipboard

TypeError: Cannot read property 'setPromisesDependency' of undefined

Open nicekiwi opened this issue 7 years ago • 5 comments

If I run the following code with Jest, I get:

TypeError: Cannot read property 'setPromisesDependency' of undefined

      at node_modules/aws-sdk-mock/index.js:252:43
      at Object.<anonymous> (node_modules/aws-sdk-mock/index.js:262:3)
      at Object.<anonymous> (__tests__/main.js:4:11)
          at Generator.next (<anonymous>)
          at new Promise (<anonymous>)
          at Generator.next (<anonymous>)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

The test:

// __tests__/main.js
'use strict'

const sinon = require('sinon')
var AWS = require('aws-sdk-mock');
var AWS_SDK = require('aws-sdk')

AWS.setSDKInstance(AWS_SDK);

/* MOCKS */

let obj = { a: 1 }
let bucket = null, key = { path: null, data: null }

AWS.mock('S3', 'createBucket', (params, callback) => {
  bucket = params.Bucket
  callback()
})

AWS.mock('S3', 'getObject', (params, callback) => {
  if (params.Key !== key.path) callback({ errorCode: 'NoSuchKey' })
  else if (!params.Bucket) callback({ errorCode: 'NoSuchBucket' })
  else callback(null, { Body: key.data })
})

AWS.mock('S3', 'putObject', (params, callback) => {
  key.path = params.Key
  key.data = params.Body
  callback()
})

nicekiwi avatar Dec 09 '17 04:12 nicekiwi

Actually it seems calling

var AWS = require('aws-sdk-mock');

on it's own will return the same error.

nicekiwi avatar Dec 09 '17 09:12 nicekiwi

@nicekiwi how did you resolve this? Getting the same thing.

rcwestlake avatar May 03 '19 02:05 rcwestlake

Hmm, I don't think I ever got this working. Found it easier to write my own mocks. https://github.com/nicekiwi/lowdb-adapter-aws-s3/blob/master/mocks/aws-sdk.js

nicekiwi avatar May 03 '19 07:05 nicekiwi

I got this error due to the fact that jest had been used to mock aws-sdk in another test and it was never unmocked. That mock did not contain a config object, and therefore this exception resulted. My advice would be to ensure that aws-sdk is what you expect it to be in your test environment. Once I had ensured aws-sdk was the genuine SDK, aws-sdk-mock worked perfectly.

th3morg avatar Aug 21 '19 18:08 th3morg

I got this error similar to @th3morg but I had a __mocks__/aws-sdk.js defined. once I deleted/renamed mock file, fixed.

electblake avatar Apr 03 '20 22:04 electblake