UNPKG

jest-aws-client-mock

Version:
66 lines (65 loc) 3.5 kB
/// <reference types="jest" /> import type { Client, MetadataBearer, Command, SdkError } from '@aws-sdk/types'; /** * Mocks an aws sdk client. */ export declare const mockClient: <TInput extends object, TOutput extends MetadataBearer>(client: InstanceOrClassType<Client<TInput, TOutput, any>>) => AwsMock<TInput, TOutput>; export declare type AwsClientMock<TClient extends Client<any, any, any>> = TClient extends Client<infer TInput, infer TOutput, any> ? AwsMock<TInput, TOutput> : never; export declare class AwsMock<TInput extends object, TOutput extends MetadataBearer> { _isMockFunction: boolean; private send; constructor(send: SpyInstance<TInput, TOutput>); /** * Does everything that `mockFn.mockClear()` does, and also removes any mocked return values or implementations. */ mockReset(): this; /** * Does everything that `mockFn.mockReset()` does, and also restores the original (non-mocked) implementation. */ mockRestore(): void; /** * Resets all information stored in the mockFn.mock.calls and mockFn.mock.instances arrays. */ mockClear(): this; get mock(): jest.MockContext<void | Promise<TOutput>, [command: Command<TInput, TInput, TOutput, TOutput, any>, options?: any, cb?: Callback<TOutput> | undefined]>; /** * Sets the name of the mock. */ mockName(name: string): this; /** * Returns the mock name string set by calling mockFn.mockName(value). */ getMockName(): string; /** * Simple sugar function for: mockFn.mockImplementation(() => Promise.resolve(value)); */ mockResolvedValue(value: CommandOutput<TOutput>): this; /** * Simple sugar function for: mockFn.mockImplementationOnce(() => Promise.resolve(value)); */ mockResolvedValueOnce(value: CommandOutput<TOutput>): this; /** * Simple sugar function for: mockFn.mockImplementation(() => Promise.reject(value)); */ mockRejectedValue(error: string | Error | SdkError): this; /** * Simple sugar function for: mockFn.mockImplementationOnce(() => Promise.reject(value)); */ mockRejectedValueOnce(error: string | Error | SdkError): this; /** * Accepts a function that should be used as the implementation of the mock. The mock itself will still record all calls that go into and instances that come from itself – the only difference is that the implementation will also be executed when the mock is called. */ mockImplementation(fn?: ((command: Command<TInput, TInput, TOutput, TOutput, any>, options?: any, cb?: Callback<TOutput>) => void | CommandOutput<TOutput>) | undefined): this; /** * Accepts a function that will be used as an implementation of the mock for one call to the mocked function. Can be chained so that multiple function calls produce different results. */ mockImplementationOnce(fn: (command: Command<TInput, TInput, TOutput, TOutput, any>, options?: any, cb?: Callback<TOutput>) => void | CommandOutput<TOutput>): this; } declare type ClassType<T> = { prototype: T; }; declare type InstanceOrClassType<T> = T | ClassType<T>; declare type Callback<T> = (err: any, data?: T | undefined) => void; declare type CommandOutput<T> = Partial<T> | Promise<Partial<T>>; declare type SpyInstance<TInput extends object, TOutput extends MetadataBearer> = jest.SpyInstance<void | Promise<TOutput>, [command: Command<TInput, TInput, TOutput, TOutput, any>, options?: any, cb?: Callback<TOutput>]>; export {};