Skip to content

Commit 79929ae

Browse files
committed
fix(jest): allow "toHaveReceivedCommandWith" partial match without required Command fields
1 parent 97ae3cd commit 79929ae

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

packages/aws-sdk-client-mock-jest/src/jestMatchers.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ interface AwsSdkJestMockBaseMatchers<R> extends Record<string, Function> {
6969
toHaveReceivedCommandWith<TCmdInput extends object,
7070
TCmdOutput extends MetadataBearer>(
7171
command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>,
72-
input: {
72+
input: Partial<{
7373
[Property in keyof TCmdInput]: unknown;
74-
},
74+
}>,
7575
): R;
7676

7777
/**
@@ -97,9 +97,9 @@ interface AwsSdkJestMockBaseMatchers<R> extends Record<string, Function> {
9797
TCmdOutput extends MetadataBearer>(
9898
call: number,
9999
command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>,
100-
input: {
100+
input: Partial<{
101101
[Property in keyof TCmdInput]: unknown;
102-
},
102+
}>,
103103
): R;
104104

105105
/**
@@ -124,9 +124,9 @@ interface AwsSdkJestMockBaseMatchers<R> extends Record<string, Function> {
124124
toHaveReceivedNthSpecificCommandWith<TCmdInput extends object, TCmdOutput extends MetadataBearer>(
125125
call: number,
126126
command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>,
127-
input: {
127+
input: Partial<{
128128
[Property in keyof TCmdInput]: unknown;
129-
},
129+
}>,
130130
): R;
131131

132132
/**
@@ -159,9 +159,9 @@ interface AwsSdkJestMockAliasMatchers<R> extends Record<string, Function> {
159159
toReceiveCommandWith<TCmdInput extends object,
160160
TCmdOutput extends MetadataBearer>(
161161
command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>,
162-
input: {
162+
input: Partial<{
163163
[Property in keyof TCmdInput]: unknown;
164-
},
164+
}>,
165165
): R;
166166

167167
/**
@@ -171,9 +171,9 @@ interface AwsSdkJestMockAliasMatchers<R> extends Record<string, Function> {
171171
TCmdOutput extends MetadataBearer>(
172172
call: number,
173173
command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>,
174-
input: {
174+
input: Partial<{
175175
[Property in keyof TCmdInput]: unknown;
176-
},
176+
}>,
177177
): R;
178178

179179
/**
@@ -182,9 +182,9 @@ interface AwsSdkJestMockAliasMatchers<R> extends Record<string, Function> {
182182
toReceiveNthSpecificCommandWith<TCmdInput extends object, TCmdOutput extends MetadataBearer>(
183183
call: number,
184184
command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>,
185-
input: {
185+
input: Partial<{
186186
[Property in keyof TCmdInput]: unknown;
187-
},
187+
}>,
188188
): R;
189189

190190
/**

packages/aws-sdk-client-mock-jest/test-d/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ expect(mockClient(SNSClient)).toHaveReceivedCommandTimes(PublishCommand, 1);
1515
expectError(expect(mockClient(SNSClient)).toHaveReceivedCommandTimes(PublishCommand));
1616

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

2021
expect(mockClient(SNSClient)).toHaveReceivedNthCommandWith(1, PublishCommand, {Message: ''});
22+
expect(mockClient(SNSClient)).toHaveReceivedNthCommandWith(1, PublishCommand, {TopicArn: ''});
2123
expectError(expect(mockClient(SNSClient)).toHaveReceivedNthCommandWith(1, PublishCommand, {Foo: ''}));
2224

25+
expect(mockClient(SNSClient)).toHaveReceivedNthSpecificCommandWith(1, PublishCommand, {Message: ''});
26+
expect(mockClient(SNSClient)).toHaveReceivedNthSpecificCommandWith(1, PublishCommand, {TopicArn: ''});
27+
expectError(expect(mockClient(SNSClient)).toHaveReceivedNthSpecificCommandWith(1, PublishCommand, {Foo: ''}));
28+
2329
globalsExpect(mockClient(SNSClient)).toHaveReceivedCommand(PublishCommand);

0 commit comments

Comments
 (0)