Created
March 19, 2018 23:16
-
-
Save ondrej-kvasnovsky/71e154bacb4a85a7c679a47e09574ab6 to your computer and use it in GitHub Desktop.
Mock AWS S3 in JavaScript using Mocha and Sinon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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