AWS SDK Vitest Mock - A powerful, type-safe mocking library for AWS SDK v3 with Vitest
import { mockClient } from 'aws-sdk-vitest-mock';import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3';const s3Mock = mockClient(S3Client);s3Mock.on(GetObjectCommand).resolves({ Body: 'file contents' });const client = new S3Client({});const result = await client.send(new GetObjectCommand({ Bucket: 'test', Key: 'file.txt' })); Copy
import { mockClient } from 'aws-sdk-vitest-mock';import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3';const s3Mock = mockClient(S3Client);s3Mock.on(GetObjectCommand).resolves({ Body: 'file contents' });const client = new S3Client({});const result = await client.send(new GetObjectCommand({ Bucket: 'test', Key: 'file.txt' }));
import { expect } from 'vitest';import { matchers } from 'aws-sdk-vitest-mock';expect.extend(matchers);expect(s3Mock).toHaveReceivedCommand(GetObjectCommand); Copy
import { expect } from 'vitest';import { matchers } from 'aws-sdk-vitest-mock';expect.extend(matchers);expect(s3Mock).toHaveReceivedCommand(GetObjectCommand);
AWS SDK Vitest Mock - A powerful, type-safe mocking library for AWS SDK v3 with Vitest
Example: Basic Setup
Example: Using Matchers