When some client has multiple instances, and we do remock, not all instances are updated
Closed this issue ยท 2 comments
ellenaua commented
Issues
- When some client has multiple instances, and we do remock, not all instances are updated
- When some client has multiple instances, and we do restore, not all instances are restored
How to reproduce issue 1
// mock DynamoDB.getItem
awsMock.mock('DynamoDB', 'getItem', function(params, callback){
callback(null, 'value1');
});
// you have multiple instances in your code
const ddb1 = new AWS.DynamoDB();
const ddb2 = new AWS.DynamoDB();
awsMock.remock('DynamoDB', 'getItem', function(params, callback){
callback(null, 'value2');
});
Currently, only ONE of instances is updated in this case, and that is strange.
ddb1.getItem()
returns value1, and ddb2.getItem()
returns value2.
How to reproduce issue 2
awsMock.mock('SNS', 'publish', function(params, callback){
callback(null, 'message');
});
const sns1 = new AWS.SNS();
const sns2 = new AWS.SNS();
// publish function on both instances is mocked
st.equals(AWS.SNS.isSinonProxy, true);
st.equals(sns1.publish.isSinonProxy, true);
st.equals(sns2.publish.isSinonProxy, true);
awsMock.restore('SNS', 'publish');
// only publish function on second instance (sns2) is restored
Pull request with fix
I opened a pull request with fix #218
nelsonic commented
@ellenaua apologies for the delay getting to this. โ
This will be a legit use case for some people. ๐
Ideally we would also add to the Docs so people know it's possible to mock multiple instances. ๐
Your PR has been merged. โ
New version published to NPM: aws-sdk-mock@5.4.0
๐ฆ
Invitation to be a maintainer of the repo sent. โ๏ธ