Skip to content

Commit

Permalink
fix(jest): match input type accepting @jest/globals asymmetric matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
m-radzikowski committed Jun 1, 2024
1 parent 7acde27 commit 644a603
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
24 changes: 18 additions & 6 deletions packages/aws-sdk-client-mock-jest/src/jestMatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ interface AwsSdkJestMockBaseMatchers<R> extends Record<string, Function> {
toHaveReceivedCommandWith<TCmdInput extends object,
TCmdOutput extends MetadataBearer>(
command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>,
input: Partial<TCmdInput>,
input: {
[Property in keyof TCmdInput]: unknown;
},
): R;

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

/**
Expand All @@ -120,7 +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: Partial<TCmdInput>,
input: {
[Property in keyof TCmdInput]: unknown;
},
): R;

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

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

/**
Expand All @@ -172,7 +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: Partial<TCmdInput>,
input: {
[Property in keyof TCmdInput]: unknown;
},
): R;

/**
Expand Down
9 changes: 9 additions & 0 deletions packages/aws-sdk-client-mock-jest/test/jestGlobals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ it('passes using @jest/globals', async () => {

expect(() => expect(snsMock).toHaveReceivedCommand(PublishCommand)).not.toThrow();
});

it('accepts asymmetric matchers with @jest/globals', async () => {
const sns = new SNSClient({});
await sns.send(publishCmd1);

expect(() => expect(snsMock).toHaveReceivedCommandWith(PublishCommand, {
Message: expect.stringContaining('mock'),
})).not.toThrow();
});

0 comments on commit 644a603

Please sign in to comment.