Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda