Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
Pass AWS SQSClient mockClient to a typescript class

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This worked for me:

const sqsClient = new SQSClient({});
const sqsMockClient = mockClient(sqsClient);
sqsMockClient.onAnyCommand().resolves({});

const blClass: BLClass = new BLClass(sqsClient);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!