{"id":15396590,"url":"https://github.com/hupe1980/jest-aws-client-mock","last_synced_at":"2025-04-16T00:18:31.222Z","repository":{"id":45086236,"uuid":"416031439","full_name":"hupe1980/jest-aws-client-mock","owner":"hupe1980","description":"Jest mock for AWS SDK v3 Clients","archived":false,"fork":false,"pushed_at":"2022-01-10T01:04:56.000Z","size":1878,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-16T00:18:28.889Z","etag":null,"topics":["aws","aws-client","aws-sdk-v3","jest","mock"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hupe1980.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-11T17:51:22.000Z","updated_at":"2022-06-10T09:06:13.000Z","dependencies_parsed_at":"2022-08-23T12:30:26.872Z","dependency_job_id":null,"html_url":"https://github.com/hupe1980/jest-aws-client-mock","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hupe1980%2Fjest-aws-client-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hupe1980%2Fjest-aws-client-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hupe1980%2Fjest-aws-client-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hupe1980%2Fjest-aws-client-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hupe1980","download_url":"https://codeload.github.com/hupe1980/jest-aws-client-mock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249173269,"owners_count":21224511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-client","aws-sdk-v3","jest","mock"],"created_at":"2024-10-01T15:34:18.466Z","updated_at":"2025-04-16T00:18:31.206Z","avatar_url":"https://github.com/hupe1980.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jest-aws-client-mock\n![Build](https://github.com/hupe1980/jest-aws-client-mock/workflows/build/badge.svg)\n![Release](https://github.com/hupe1980/jest-aws-client-mock/workflows/release/badge.svg)\n\n\u003e Jest mock for AWS SDK v3 Clients\n\n## Installation\n```bash\n// with npm\nnpm install -D jest-aws-client-mock\n\n// with yarn\nyarn add -D jest-aws-client-mock\n```\n\n## How to use\n```typescript\nimport { PublishCommand, SNSClient } from '@aws-sdk/client-sns';\nimport { mockClient } from 'jest-aws-client-mock';\n\nconst snsMock = mockClient(SNSClient);\n\nbeforeEach(() =\u003e {\n  snsMock.mockReset();\n});\n\ntest('mock sns client', async () =\u003e {\n  expect.assertions(3);\n\n  snsMock.mockResolvedValue({\n      MessageId: '123',\n  });\n\n  const snsClient = new SNSClient({});\n\n  const command = new PublishCommand({\n      Message: 'message',\n      TopicArn: 'arn:aws:sns:us-east-1:111111111111:TestTopic',\n  });\n\n  const result = await snsClient.send(command);\n\n  expect(snsMock).toHaveBeenCalledTimes(1);\n  expect(snsMock).toHaveBeenCalledWith(command);\n  expect(result).toEqual({ MessageId: '123' })\n});\n```\n\n### DynamoDBDocumentClient\n```typescript\nimport { DynamoDBClient } from '@aws-sdk/client-dynamodb';\nimport { DynamoDBDocumentClient, GetCommand, GetCommandOutput } from '@aws-sdk/lib-dynamodb';\nimport { mockClient } from 'jest-aws-client-mock';\n\nconst ddbMock = mockClient(DynamoDBDocumentClient);\n\nbeforeEach(() =\u003e {\n  ddbMock.mockReset();\n});\n\ntest('dynamodbDocumentClient', async () =\u003e {\n  expect.assertions(3);\n\n  const output: Partial\u003cGetCommandOutput\u003e = {\n    Item: {\n      Id: '4711',\n    },\n  };\n\n  ddbMock.mockResolvedValue(output);\n\n  const command = new GetCommand({\n    TableName: 'tableName',\n    Key: {\n      Id: '4711',\n    },\n  });\n\n  const dynamodbClient = new DynamoDBClient({});\n\n  const ddb = DynamoDBDocumentClient.from(dynamodbClient);\n\n  const result = await ddb.send(command);\n\n  expect(ddbMock).toHaveBeenCalledTimes(1);\n  expect(ddbMock).toHaveBeenCalledWith(command);\n  expect(result).toEqual(output);\n});\n```\n\n### Asymetric matchers\n```typescript\nimport { PublishCommand, SNSClient } from '@aws-sdk/client-sns';\nimport { mockClient } from 'jest-aws-client-mock';\n\nconst snsMock = mockClient(SNSClient);\n\nbeforeEach(() =\u003e {\n  snsMock.mockReset();\n});\n\ntest('mock - asymetric matcher', async () =\u003e {\n  expect.assertions(1);\n\n  const snsClient = new SNSClient({});\n\n  const command = new PublishCommand({\n      Message: 'random',\n      TopicArn: 'arn:aws:sns:us-east-1:111111111111:TestTopic',\n  });\n\n  await snsClient.send(command);\n\n  expect(snsMock).toHaveBeenCalledWith(\n    expect.objectContaining({\n      input: {\n        TopicArn: 'arn:aws:sns:us-east-1:111111111111:TestTopic',\n        Message: expect.any(String),\n      },\n    }),\n  );\n});\n```\n\n## License\n[MIT](LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhupe1980%2Fjest-aws-client-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhupe1980%2Fjest-aws-client-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhupe1980%2Fjest-aws-client-mock/lists"}