Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moeriki/jest-mock-aws
https://github.com/moeriki/jest-mock-aws
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/moeriki/jest-mock-aws
- Owner: moeriki
- License: mit
- Created: 2018-09-27T10:20:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-27T15:21:52.000Z (almost 5 years ago)
- Last Synced: 2024-12-27T08:37:03.118Z (13 days ago)
- Language: JavaScript
- Homepage:
- Size: 44.9 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jest-mock-aws
Utiliy to help you mock AWS when testing with [Jest](https://jestjs.io).
You can use this only with the AWS Promise interface.
## Quick start
```sh
npm install --save-dev jest-mock-aws
```### _index.js_
```js
exports.publish = (message) => new AWS.SNS().publish(message).promise();
```### _index.test.js_
```js
const AWS = require('aws-sdk');
const { mockAwsServiceMethod } = require('jest-mock-aws');jest.mock('aws-sdk', () => ({}));
it('should mock AWS', () => {
const mockPublish = mockAwsServiceMethod(AWS, 'SNS', 'publish');
mockPublish.mockResolvedValue('publish-result');
});
```## API
### mockAwsService
#### `mockAwsService(AWS:object, serviceName:string) :object`
```js
const AWS = {};
const mockSns = mockAwsService(AWS, 'SNS');
mockSns.publish = jest.fn();
mockSns.publish.mockResolvedValue({});
```### mockAwsServiceMethod
#### `mockAwsServiceMethod(AWS:object, serviceName:string, methodName:String) :jest.fn()`
```js
const AWS = {};
const mockSnsPublish = mockAwsServiceMethod(AWS, 'SNS', 'publish');
mockSnsPublish.mockResolvedValue({});
```### mockAwsServiceMethods
#### `mockAwsServiceMethods(AWS:object, serviceName:string, methods:Array|Object) :object`
With Array.
```js
const AWS = {};
const mockSqs = mockAwsServiceMethods(AWS, 'SQS', [
'deleteMessage',
'receiveMessages',
]);
mockSqs.deleteMessage.mockResolvedValue({});
mockSqs.receiveMessages.mockResolvedValue({});
```With Object.
```js
const AWS = {};
const mockSqs = mockAwsServiceMethods(AWS, 'SQS', {
deleteMessage: jest.fn().mockResolvedValue({});
receiveMessages: jest.fn().mockResolvedValue({});
});
```