I'm trying to unit test some code where the class has a constructor taking in an SQSClient object used to get messages off an sqs queue! Surprise! Very simple stuff. So I want to mock the client so I can write some unit tests around the code without actually calling the queue. I'm trying to model my code from examples here:
https://www.npmjs.com/package/aws-sdk-client-mock
In my unit test I simply create the mock client and try to pass it into my class:
const sqsMockClient = mockClient(SQSClient);
sqsMockClient.onAnyCommand().resolves({});
const blClass: BLClass = new BLClass(sqsMockClient);
This won't run, the test output says the type is not assignable to parameter of type 'SQSClient' because it's not an actual SQSClient. If I instantiate an actual SQSClient and pass that it will run but will attempt to actually hit the queue and pull messages down. I'm wanting to build out the mock above to return a static message for unit testing purposes.
Any idea what I could do differently to enable the mock to work?
This worked for me:
const sqsClient = new SQSClient({});
const sqsMockClient = mockClient(sqsClient);
sqsMockClient.onAnyCommand().resolves({});
const blClass: BLClass = new BLClass(sqsClient);