Jest Typescript cannot mock AWS transcribe function

0 votes

I've been trying to figure out how to implement the jest testing solution provided here (vanilla js) by the AWS team to work and so far I can't seem to make any headway. I get an error at .mockResolvedValue(expectedResult) as "Argument of type '{ isMock: boolean; }' is not assignable to parameter of type 'never'." However, I can't find a way to get around it. The function is cast above the describe block and follows the pattern shown at this StackOverflow post.

Any thoughts on what I'm doing wrong? I'm not super familiar with mocking like this so I could be missing something obvious. Also the pattern I have is pretty much the same as the code snippets AWS provides in the initial link.

transcribe client

import { TranscribeClient } from '@aws-sdk/client-transcribe';
const REGION = 'us-east-2';
// Create Transcribe service object.
export const transcribeClient = new TranscribeClient({ region: REGION });

transcribe test

import { createTranscribeJob } from './createJob';
import { transcribeClient } from '../../../../libs/transcribeClient';

jest.mock('../../../../libs/transcribeClient.ts');

const mockedTranscribeClient = transcribeClient as jest.Mocked<typeof transcribeClient>;

describe('@aws-sdk/client-transcribe mock', () => {
  it('should successfully mock Transcribe client', async () => {

    const expectedResult: { isMock: boolean } = { isMock: true };
    mockedTranscribeClient.send.mockResolvedValue(expectedResult);
    const response = await createTranscribeJob({
      TranscriptionJobName: 'testName',
      LanguageCode: 'en-US',
      MediaFormat: 'mp4',
      MediaUri: 'testUri',
    });

    expect(response.isMock).toEqual(true);

  });
});
Jul 14, 2022 in TypeSript by Logan
• 2,140 points
1,199 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In TypeSript

0 votes
1 answer

TypeScript error TS2304: cannot find name ' require'

Here's a really easy work around: declare var ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
13,907 views
0 votes
1 answer

Typescript: Can't find names - Error: cannot find name

A known issue: https://github.com/angular/angular/issues/4902 Core reason: the .d.ts file implicitly included ...READ MORE

answered Jun 7, 2022 in TypeSript by Nina
• 3,060 points
11,505 views
0 votes
1 answer

Destructure a function parameter in Typescript

You can use the object de-structuring syntax: createUser(parent: ...READ MORE

answered Jun 9, 2022 in TypeSript by Nina
• 3,060 points
902 views
0 votes
1 answer
0 votes
0 answers

Function definition syntax confuse in Typescript

I figure that out: One post in ...READ MORE

Jul 5, 2022 in TypeSript by Nina
• 3,060 points
568 views
0 votes
0 answers

In typescript, why do the | and & operators flip their meaning when used on function types?

In this code, example1 and example2 are confusing me: type F1 = ...READ MORE

Jul 13, 2022 in TypeSript by Logan
• 2,140 points
530 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP