dwyl / aws-sdk-mock

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

Calling stubbed methods without a callback #36

Open rclark opened 8 years ago

rclark commented 8 years ago

In https://github.com/dwyl/aws-sdk-mock/pull/24 logic was introduced that forks the way a service method is mocked depending on whether or not a callback is provided.

The aws-sdk has always returned an AWS.Request object in response to a method call, regardless of whether or not you provided a callback. This object is an event emitter, in addition to providing a .promise property and several other of its own methods.

Before #24, if I wanted to mock the request object, I would do something like:

AWS.mock('s3', 'putObject', function() {
  var request = new events.EventEmitter();
  // ... etc ...
  return request;
});

... and I could use this to test logic like:

s3.putObject(parms)
  .on('error', function(err) { })
  .on('success', function() {} );

Now I can't do this -- once I call .putObject without a callback I have no access to the replacement function without using the .promise property.

This is kinda rambling, but my point is that you're now mocking the AWS.Request object, but only one of its properties, making it impossible for me to use this library to mock the AWS.Request object myself.

benrki commented 8 years ago

Would also like a way to mock the createReadStream method of the AWS.Request object in particular (for S3.getObject calls).