Getting error - TypeError: Cannot read properties of undefined (reading 'isSinonProxy')

532 views Asked by At

I'm trying to mock DocumentClient using aws-sdk-client-mock.

import  { mockClient } from 'aws-sdk-client-mock';
import { DocumentClient } from 'aws-sdk/clients/dynamodb';

const mockDocClient = mockClient(DocumentClient);

I'm getting the error TypeError: Cannot read properties of undefined (reading 'isSinonProxy').

Does anyone know where should I set this value?

1

There are 1 answers

0
Artem On

You just need to check that DocumentClient was not mocked before calling mockClient function.

At least for me this error happens when I trying to mock already mocked CognitoIdentityProviderClient class.

import { mockClient } from "aws-sdk-client-mock";
import {
    CognitoIdentityProviderClient,
    AssociateSoftwareTokenCommand,
} from "@aws-sdk/client-cognito-identity-provider";

jest.mock('@aws-sdk/client-cognito-identity-provider', () => ({
  CognitoIdentityProviderClient: jest.fn().mockImplementation(() => ({
    send: jest.fn(),
  })),
....

const cognitoIdentityProviderClientMock = mockClient(CognitoIdentityProviderClient);
cognitoIdentityProviderClientMock
    .on(AssociateSoftwareTokenCommand, {
      AccessToken: accessToken,
    })
    .resolves({});

In my case part with jest.mock for CognitoIdentityProviderClient causes the problem.