m-radzikowski / aws-sdk-client-mock

AWS JavaScript SDK v3 mocks for easy unit testing. πŸ–‹οΈ Typed πŸ”¬ Tested πŸ“„ Documented πŸ› οΈ Maintained
https://m-radzikowski.github.io/aws-sdk-client-mock/
MIT License
791 stars 39 forks source link

Unable to pass mock SQSClient to property typed as SQSClient #233

Open dmeehan1968 opened 2 months ago

dmeehan1968 commented 2 months ago

Checklist

Bug description

Relates to #197

I've tried all of the suggestions here but the reported type problem is always the same.

Screenshot 2024-07-13 at 12 45 28

I can workaround the problem using the as unknown as SQSCLient override.

Note that there is a conflict for @smithy/types in @aws-lambda-powertools/tracer, but even when following the steps in #197, removing the dependency or creating an override didn't resolve the issue.

I use Jetbrains PHPStorm 2024.2 EAP as my IDE.

Reproduction

const mockSqsClient = mockClient(SQSClient)
const client: SQSClient = mockSqsClient

Environment

    "@types/jest": "^29.5.12",
    "jest": "^29.7.0",
    "jest-mock-extended": "^3.0.7",
    "ts-jest": "^29.2.2",
    "ts-node": "^10.9.2",
    "aws-sdk-client-mock": "^4.0.1",
    "aws-sdk-client-mock-jest": "^4.0.1",
    "@aws-cdk/aws-iot-actions-alpha": "^2.148.1-alpha.0",
    "@aws-cdk/aws-iot-alpha": "^2.148.1-alpha.0",
    "@aws-lambda-powertools/logger": "^2.4.0",
    "@aws-lambda-powertools/metrics": "^2.4.0",
    "@aws-lambda-powertools/tracer": "^2.4.0",
    "@aws-sdk/client-dynamodb": "^3.614.0",
    "@aws-sdk/client-eventbridge": "^3.614.0",
    "@aws-sdk/client-sqs": "^3.614.0",
    "@aws-sdk/client-timestream-query": "^3.614.0",
    "@aws-sdk/client-timestream-write": "^3.614.0",
    "@aws-sdk/lib-dynamodb": "^3.614.0",
    "@middy/core": "^5.4.3",
    "@types/aws-lambda": "^8.10.141",
    "aws-cdk-lib": "^2.148.1",
β”œβ”€β”¬ @aws-lambda-powertools/tracer@2.4.0
β”‚ └─┬ aws-xray-sdk-core@3.9.0
β”‚   └─┬ @smithy/service-error-classification@2.1.5
β”‚     └── @smithy/types@2.12.0
β”œβ”€β”¬ @aws-sdk/client-dynamodb@3.614.0
β”‚ β”œβ”€β”¬ @aws-sdk/client-sso-oidc@3.614.0
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @aws-sdk/client-sts@3.614.0
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @aws-sdk/core@3.614.0
β”‚ β”‚ β”œβ”€β”¬ @smithy/signature-v4@3.1.2
β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @aws-sdk/credential-provider-node@3.614.0
β”‚ β”‚ β”œβ”€β”¬ @aws-sdk/credential-provider-env@3.609.0
β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ β”œβ”€β”¬ @aws-sdk/credential-provider-http@3.614.0
β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ β”œβ”€β”¬ @aws-sdk/credential-provider-ini@3.614.0
β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ β”œβ”€β”¬ @aws-sdk/credential-provider-process@3.614.0
β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ β”œβ”€β”¬ @aws-sdk/credential-provider-sso@3.614.0
β”‚ β”‚ β”‚ β”œβ”€β”¬ @aws-sdk/client-sso@3.614.0
β”‚ β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ β”‚ β”œβ”€β”¬ @aws-sdk/token-providers@3.614.0
β”‚ β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ β”œβ”€β”¬ @aws-sdk/credential-provider-web-identity@3.609.0
β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ β”œβ”€β”¬ @smithy/credential-provider-imds@3.1.4
β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ β”œβ”€β”¬ @smithy/property-provider@3.1.3
β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ β”œβ”€β”¬ @smithy/shared-ini-file-loader@3.1.4
β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @aws-sdk/middleware-endpoint-discovery@3.614.0
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @aws-sdk/middleware-host-header@3.609.0
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @aws-sdk/middleware-logger@3.609.0
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @aws-sdk/middleware-recursion-detection@3.609.0
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @aws-sdk/middleware-user-agent@3.614.0
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @aws-sdk/region-config-resolver@3.614.0
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @aws-sdk/types@3.609.0
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @aws-sdk/util-endpoints@3.614.0
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @aws-sdk/util-user-agent-browser@3.609.0
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @aws-sdk/util-user-agent-node@3.614.0
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/config-resolver@3.0.5
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/core@2.2.6
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/fetch-http-handler@3.2.1
β”‚ β”‚ β”œβ”€β”¬ @smithy/querystring-builder@3.0.3
β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/hash-node@3.0.3
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/invalid-dependency@3.0.3
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/middleware-content-length@3.0.3
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/middleware-endpoint@3.0.5
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/middleware-retry@3.0.9
β”‚ β”‚ β”œβ”€β”¬ @smithy/service-error-classification@3.0.3
β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/middleware-serde@3.0.3
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/middleware-stack@3.0.3
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/node-config-provider@3.1.4
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/node-http-handler@3.1.2
β”‚ β”‚ β”œβ”€β”¬ @smithy/abort-controller@3.1.1
β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/protocol-http@4.0.3
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/smithy-client@3.1.7
β”‚ β”‚ β”œβ”€β”€ @smithy/types@3.3.0 deduped
β”‚ β”‚ └─┬ @smithy/util-stream@3.0.6
β”‚ β”‚   └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”€ @smithy/types@3.3.0
β”‚ β”œβ”€β”¬ @smithy/url-parser@3.0.3
β”‚ β”‚ β”œβ”€β”¬ @smithy/querystring-parser@3.0.3
β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/util-defaults-mode-browser@3.0.9
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/util-defaults-mode-node@3.0.9
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/util-endpoints@2.0.5
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/util-middleware@3.0.3
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/util-retry@3.0.3
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ └─┬ @smithy/util-waiter@3.1.2
β”‚   └── @smithy/types@3.3.0 deduped
β”œβ”€β”¬ @aws-sdk/client-eventbridge@3.614.0
β”‚ β”œβ”€β”¬ @aws-sdk/middleware-signing@3.609.0
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @aws-sdk/signature-v4-multi-region@3.614.0
β”‚ β”‚ β”œβ”€β”¬ @aws-sdk/middleware-sdk-s3@3.614.0
β”‚ β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ └── @smithy/types@3.3.0 deduped
β”œβ”€β”¬ @aws-sdk/client-sqs@3.614.0
β”‚ β”œβ”€β”¬ @aws-sdk/middleware-sdk-sqs@3.614.0
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ β”œβ”€β”¬ @smithy/md5-js@3.0.3
β”‚ β”‚ └── @smithy/types@3.3.0 deduped
β”‚ └── @smithy/types@3.3.0 deduped
β”œβ”€β”¬ @aws-sdk/client-timestream-query@3.614.0
β”‚ └── @smithy/types@3.3.0 deduped
β”œβ”€β”¬ @aws-sdk/client-timestream-write@3.614.0
β”‚ └── @smithy/types@3.3.0 deduped
└─┬ @aws-sdk/lib-dynamodb@3.614.0
  └── @smithy/types@3.3.0 deduped
pappnase99 commented 5 days ago

Facing a similar issue, I'm basically trying to do something like this:

import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
import { mockClient } from 'aws-sdk-client-mock';

let dynamoDbDocumentClient: DynamoDBDocumentClient;
dynamoDbDocumentClient = mockClient(DynamoDBDocumentClient);

And I get the error Type 'AwsStub<ServiceInputTypes, ServiceOutputTypes, DynamoDBDocumentClientResolvedConfig>' is missing the following properties from type 'DynamoDBDocumentClient': config, destroy, middlewareStack

Dependencies:

"@aws-sdk/lib-dynamodb": "^3.650.0",
"aws-sdk-client-mock": "^4.0.1",

npm ls shows @smithy/types@3.4.0