aws-sdk-mock: getSignedUrl doesn't mock correctly when called asynchronously
code:
AWSMock.mock('S3', 'getSignedUrl', 'message');
const s3 = new AWS.S3({ paramValidation: true }),
const s3Url = s3.getSignedUrl('getObject', {Key: 'key', Bucket: 'Bucket'});
console.log(s3Url); //should be a string... However it looks more like an AWS Request object:
Output:
{ promise: [Function],
createReadStream: [Function: createReadStream],
on: [Function: on],
send: [Function: send] }
Please review the documentation for further information: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 32
- Comments: 16
I had the same issue with this code:
and my test:
so, I changed my code to this, and then my test worked!
we should not change implementation of our code to pass tests but rather the aws-sdk-mock should support mocking of all features of aws-sdk
It seems this has something to do with the assumption that all the AWS service methods should have the signature service(params, callback)
getSignalUrl has the following signature: getSignalUrl(method,params, callback)
I’d really appreciate it if this could be fixed
Just ran over this issue on a project and @yoelfme 's approach was very helpful for my case, with the difference that i already was using the
s3.getSignedUrlPromisemethod, so i just had to create a mock fors3.getSignedUrland that was enough for the test to work without problems.It seems that this library only mocks methods that return instances of the Request<D, E> class. However, there are lots of methods that don’t return such instances, for example, the aforementioned getSignedUrl. Are there future plans to add the possibility to mock such methods?
Also experiencing this issue.
So I ran into this issue also, I was able to get around it for now with mocking the getSignedUrlPromise function manually:
This allowed me to mock the getSignedUrlPromise function whilst also mocking others. The issue I had with the others was when I injected the manually mocked functions whilst using aws-sdk-mock I was losing all reference to the stubs previously in place, so I have simply not used this repo for this functions unit tests. Not a great solution but might be helpful for others that need a solution now.