Closed thevictorchang closed 2 months ago
I'm getting a similar error with a class's constructor not able to take the mocked client but I'm trying to mock the SNSClient.
I actually get a type error if I fully type the output of mockClient
const thing: AwsClientStub<SNSClient> = mockClient(SNSClient);
Type 'AwsStub<ServiceInputTypes, ServiceOutputTypes, SmithyResolvedConfiguration<HttpHandlerOptions>>' is not assignable to type 'AwsStub<ServiceInputTypes, ServiceOutputTypes, SNSClientResolvedConfig>'.
Type 'SmithyResolvedConfiguration<HttpHandlerOptions>' is not assignable to type 'SNSClientResolvedConfig'.
Type 'SmithyResolvedConfiguration<HttpHandlerOptions>' is missing the following properties from type 'Required<ClientDefaults>': sha256, urlParser, bodyLengthChecker, streamCollector, and 17 more.ts(2322)
That gives me a Smithy-types error that the caveats section was unable to resolve.
This seems to be broken in the latest STSClient currently at version (3.575.0
):
https://www.npmjs.com/package/@aws-sdk/client-sts/v/3.575.0
It works in the previous version (3.574.0
):
https://www.npmjs.com/package/@aws-sdk/client-sts/v/3.574.0
Seems like the 3.575.0
release includes som breaking changes regarding smithy https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.575.0
In my STSClient case: https://github.com/aws/aws-sdk-js-v3/commit/6877db975b7676ae9535cc4a072828a855de8f5f#diff-c00e767676da286301fe37f850b4c4cdaa0bf86930bcb97a454342605f95938e
Same problem here with SNSClient or others AWS clients
EDIT : They migrate some parts to Smithy packages : https://github.com/aws/aws-sdk-js-v3/issues/5102
Maybe this package needs upgrade to add compatibility with this part.
Looks like there have been similar issues before: https://github.com/m-radzikowski/aws-sdk-client-mock/issues/197
I wonder if this is a new problem or the same? Although the major change in smithy smells bad 👃
We've found a workaround:
const ecsClientMock = mockClient(ECSClient);
const ecsClient = (ecsClientMock as unknown) as ECSClient;
We can mock the result of commands with ecsClientMock.on(ListTaskscommand).resolves({ ... })
but pass in the ecsClient
where it's needed. Not sure if this is the intended workaround...
Fixed by: https://github.com/m-radzikowski/aws-sdk-client-mock/issues/197
I cannot even create mock with sesv2@3.576.0
error when trying to create a mock:
test/verifier.test.ts:15:26 - error TS2345: Argument of type 'typeof SESv2Client' is not assignable to parameter of type 'InstanceOrClassType<Client<ServiceInputTypes, MetadataBearer, SmithyResolvedConfiguration<HttpHandlerOptions>>>'.
15 const sesStub = mock(SESv2Client);
~~~~~~~~~~~
test/verifier.test.ts:30:13 - error TS2345: Argument of type 'typeof GetEmailIdentityCommand' is not assignable to parameter of type 'new (input: GetEmailIdentityCommandInput) => AwsCommand<GetEmailIdentityCommandInput, MetadataBearer, any, any>'.
Construct signature return types 'GetEmailIdentityCommand' and 'AwsCommand<GetEmailIdentityCommandInput, MetadataBearer, any, any>' are incompatible.
The types of 'middlewareStack.concat' are incompatible between these types.
Type '<InputType extends GetEmailIdentityCommandInput, OutputType extends GetEmailIdentityCommandOutput>(from: MiddlewareStack<InputType, OutputType>) => MiddlewareStack<...>' is not assignable to type '<InputType extends GetEmailIdentityCommandInput, OutputType extends MetadataBearer>(from: MiddlewareStack<InputType, OutputType>) => MiddlewareStack<...>'.
Types of parameters 'from' and 'from' are incompatible.
Type 'MiddlewareStack<InputType, OutputType>' is not assignable to type 'MiddlewareStack<InputType, GetEmailIdentityCommandOutput>'.
Types of property 'addRelativeTo' are incompatible.
Type '(middleware: MiddlewareType<InputType, OutputType>, options: RelativeMiddlewareOptions) => void' is not assignable to type '(middleware: MiddlewareType<InputType, GetEmailIdentityCommandOutput>, options: RelativeMiddlewareOptions) => void'.
Types of parameters 'middleware' and 'middleware' are incompatible.
Type 'MiddlewareType<InputType, GetEmailIdentityCommandOutput>' is not assignable to type 'MiddlewareType<InputType, OutputType>'.
Type 'InitializeMiddleware<InputType, GetEmailIdentityCommandOutput>' is not assignable to type 'MiddlewareType<InputType, OutputType>'.
Type 'InitializeMiddleware<InputType, GetEmailIdentityCommandOutput>' is not assignable to type 'InitializeMiddleware<InputType, OutputType>'.
Call signature return types 'InitializeHandler<InputType, GetEmailIdentityCommandOutput>' and 'InitializeHandler<InputType, OutputType>' are incompatible.
Type 'Promise<InitializeHandlerOutput<GetEmailIdentityCommandOutput>>' is not assignable to type 'Promise<InitializeHandlerOutput<OutputType>>'.
Type 'InitializeHandlerOutput<GetEmailIdentityCommandOutput>' is not assignable to type 'InitializeHandlerOutput<OutputType>'.
Types of property 'output' are incompatible.
Type 'GetEmailIdentityCommandOutput' is not assignable to type 'OutputType'.
'GetEmailIdentityCommandOutput' is assignable to the constraint of type 'OutputType', but 'OutputType' could be instantiated with a different subtype of constraint 'MetadataBearer'.
and I cannot call expect
test/verifier.test.ts:43:45 - error TS2345: Argument of type 'typeof GetEmailIdentityCommand' is not assignable to parameter of type 'new (input: GetEmailIdentityCommandInput) => AwsCommand<GetEmailIdentityCommandInput, MetadataBearer>'.
Type 'GetEmailIdentityCommand' is not assignable to type 'AwsCommand<GetEmailIdentityCommandInput, MetadataBearer>'.
43 expect(sesStub).toHaveReceivedCommand(GetEmailIdentityCommand);
I'm also having this issue with the EC2Client
Any news about that ?
With both @aws-sdk/client-ecs
v3.575.0 and v3.588.0 (current latest) the mockClient(ECSClient)
works fine without type errors. Same for EC2 client.
The package.json
:
"@aws-sdk/client-ecs": "^3.109.0",
means any version between 3.109.0 and 4.0.0. If you have @aws-sdk/*
packages in different versions installed, they can install separate types in different versions, leading to this problem.
The solution steps, as @Crafoord noted, are described in #197
If the problem persists, see the last point in the issue on providing the exact dependency versions. Even better if you create a repo with reproduction.
I'll leave it open for a bit and close later if there are no further problems.
@m-radzikowski thanks for the update!
I updated all my aws-sdk dependencies and additionally added the override and it is working for me now.
Checklist
Bug description
I did read the Caveats docs and don't think this is quite the issue that is being described there - correct me if I am wrong though.
I have a class that takes an ECSClient object (imported from @aws-sdk/client-ecs) as a parameter in it's constructor but trying to pass a mocked one in gives the error:
It seems that the type of the mocked ECSClient isn't quite what is expected, or perhaps I am misunderstanding the goal of the library?
Reproduction
Class under test:
Test file:
package.json:
Environment