aws-sdk-mock
aws-sdk-mock copied to clipboard
TypeError: Cannot read property 'setPromisesDependency' of undefined
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()
})
Actually it seems calling
var AWS = require('aws-sdk-mock');
on it's own will return the same error.
@nicekiwi how did you resolve this? Getting the same thing.
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
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.
I got this error similar to @th3morg but I had a __mocks__/aws-sdk.js defined. once I deleted/renamed mock file, fixed.