Skip to content

Commit

Permalink
fix(jest): allow "toHaveReceivedCommandWith" partial match without re…
Browse files Browse the repository at this point in the history
…quired Command fields
  • Loading branch information
m-radzikowski committed Jun 20, 2024
1 parent 97ae3cd commit 79929ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/aws-sdk-client-mock-jest/src/jestMatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ interface AwsSdkJestMockBaseMatchers<R> extends Record<string, Function> {
toHaveReceivedCommandWith<TCmdInput extends object,
TCmdOutput extends MetadataBearer>(
command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>,
input: {
input: Partial<{
[Property in keyof TCmdInput]: unknown;
},
}>,
): R;

/**
Expand All @@ -97,9 +97,9 @@ interface AwsSdkJestMockBaseMatchers<R> extends Record<string, Function> {
TCmdOutput extends MetadataBearer>(
call: number,
command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>,
input: {
input: Partial<{
[Property in keyof TCmdInput]: unknown;
},
}>,
): R;

/**
Expand All @@ -124,9 +124,9 @@ interface AwsSdkJestMockBaseMatchers<R> extends Record<string, Function> {
toHaveReceivedNthSpecificCommandWith<TCmdInput extends object, TCmdOutput extends MetadataBearer>(
call: number,
command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>,
input: {
input: Partial<{
[Property in keyof TCmdInput]: unknown;
},
}>,
): R;

/**
Expand Down Expand Up @@ -159,9 +159,9 @@ interface AwsSdkJestMockAliasMatchers<R> extends Record<string, Function> {
toReceiveCommandWith<TCmdInput extends object,
TCmdOutput extends MetadataBearer>(
command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>,
input: {
input: Partial<{
[Property in keyof TCmdInput]: unknown;
},
}>,
): R;

/**
Expand All @@ -171,9 +171,9 @@ interface AwsSdkJestMockAliasMatchers<R> extends Record<string, Function> {
TCmdOutput extends MetadataBearer>(
call: number,
command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>,
input: {
input: Partial<{
[Property in keyof TCmdInput]: unknown;
},
}>,
): R;

/**
Expand All @@ -182,9 +182,9 @@ interface AwsSdkJestMockAliasMatchers<R> extends Record<string, Function> {
toReceiveNthSpecificCommandWith<TCmdInput extends object, TCmdOutput extends MetadataBearer>(
call: number,
command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>,
input: {
input: Partial<{
[Property in keyof TCmdInput]: unknown;
},
}>,
): R;

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/aws-sdk-client-mock-jest/test-d/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ expect(mockClient(SNSClient)).toHaveReceivedCommandTimes(PublishCommand, 1);
expectError(expect(mockClient(SNSClient)).toHaveReceivedCommandTimes(PublishCommand));

expect(mockClient(SNSClient)).toHaveReceivedCommandWith(PublishCommand, {Message: ''});
expect(mockClient(SNSClient)).toHaveReceivedCommandWith(PublishCommand, {TopicArn: ''}); // partial match withouth required fields
expectError(expect(mockClient(SNSClient)).toHaveReceivedCommandWith(PublishCommand, {Foo: ''}));

expect(mockClient(SNSClient)).toHaveReceivedNthCommandWith(1, PublishCommand, {Message: ''});
expect(mockClient(SNSClient)).toHaveReceivedNthCommandWith(1, PublishCommand, {TopicArn: ''});
expectError(expect(mockClient(SNSClient)).toHaveReceivedNthCommandWith(1, PublishCommand, {Foo: ''}));

expect(mockClient(SNSClient)).toHaveReceivedNthSpecificCommandWith(1, PublishCommand, {Message: ''});
expect(mockClient(SNSClient)).toHaveReceivedNthSpecificCommandWith(1, PublishCommand, {TopicArn: ''});
expectError(expect(mockClient(SNSClient)).toHaveReceivedNthSpecificCommandWith(1, PublishCommand, {Foo: ''}));

globalsExpect(mockClient(SNSClient)).toHaveReceivedCommand(PublishCommand);

0 comments on commit 79929ae

Please sign in to comment.