aws-sdk-client-mock-jest
Version:
Custom Jest matchers for AWS SDK v3 Client mock
60 lines (59 loc) • 2.4 kB
TypeScript
import type { AnyCommand, AnySpyCall, AwsSdkMockAliasMatchers, AwsSdkMockBaseMatchers, CommonMatcherUtils, MatcherFunction } from './types';
interface MessageFunctionParams<T extends CommonMatcherUtils, CheckData = undefined> {
cmd: string;
client: string;
commandCalls: AnySpyCall[];
calls: AnySpyCall[];
data: CheckData;
notPrefix: string;
ctxUtils: T;
}
/**
* Provides {@link jest} matcher for testing {@link AwsStub} command calls
*
* @example
*
* ```ts
* import { mockClient } from "aws-sdk-client-mock";
* import { ScanCommand } from "@aws-sdk/client-dynamodb";
*
* const awsMock = mockClient(DynamoDBClient);
*
* awsMock.on(ScanCommand).resolves({
* Items: [{ Info: { S: '{ "val": "info" }' }, LockID: { S: "fooId" } }],
* });
*
* it("Should call scan command", async () => {
* // check result ... maybe :)
* await expect(sut()).resolves.toEqual({ ... });
*
* // Assert awsMock to have recevied a Scan Command at least one time
* expect(awsMock).toHaveReceivedCommand(ScanCommand);
* });
* ```
*/
export interface AwsSdkMockMatchers<R> extends AwsSdkMockBaseMatchers<R>, AwsSdkMockAliasMatchers<R>, Record<string, Function> {
}
interface MessageImpl<T extends CommonMatcherUtils> {
toHaveReceivedCommandTimes: (expectedCalls: number) => (args: MessageFunctionParams<T>) => string;
toHaveReceivedCommand: (args: MessageFunctionParams<T>) => string;
toHaveReceivedCommandWith: (input: Record<string, unknown>) => (args: MessageFunctionParams<T, {
matchCount: number;
}>) => string;
toHaveReceivedNthCommandWith: (call: number, input: Record<string, unknown>) => (args: MessageFunctionParams<T, {
received?: AnyCommand;
}>) => string;
toHaveReceivedNthSpecificCommandWith: (call: number, input: Record<string, unknown>) => (args: MessageFunctionParams<T, {
received?: AnyCommand;
}>) => string;
toHaveReceivedAnyCommand: (args: MessageFunctionParams<T>) => string;
}
export declare function createBaseMatchers<T extends CommonMatcherUtils = CommonMatcherUtils>(errorMsg: MessageImpl<T>, objectContaining: (sample: Record<string, unknown>) => {
asymmetricMatch(other: unknown): boolean;
toString(): string;
getExpectedType?(): string;
toAsymmetricMatcher?(): string;
}): {
[P in keyof AwsSdkMockBaseMatchers<unknown>]: MatcherFunction<T>;
};
export {};