Skip to content

Instantly share code, notes, and snippets.

@ondrej-kvasnovsky
Created March 19, 2018 23:16
Show Gist options
  • Save ondrej-kvasnovsky/71e154bacb4a85a7c679a47e09574ab6 to your computer and use it in GitHub Desktop.
Save ondrej-kvasnovsky/71e154bacb4a85a7c679a47e09574ab6 to your computer and use it in GitHub Desktop.
Mock AWS S3 in JavaScript using Mocha and Sinon
const SomeService = require('some/service')
const AWS = require('aws-sdk')
describe('someService', async function() {
let someService
beforeEach(async function() {
someService = new SomeService()
})
describe('upload()', async function() {
it('uploads an file', async function() {
const s3Url = 'https://dummy-bucket.amazonaws.com/somefile.txt'
this.sinon.stub(AWS, 'S3').callsFake(() => {
const upload = function() {
const promise = async function() {
return { Location: s3Url }
}
return { promise }
}
return { upload }
})
const url = await someService.upload('test/fixtures/sample-image.jpg')
expect(url).to.be.eql(s3Url)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment