Created
August 13, 2017 19:13
-
-
Save erika-dike/4bf8eaba576da52cd1f39f56eec466b5 to your computer and use it in GitHub Desktop.
This file contains 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
describe('openCloudinaryUploadWidget test suite', () => { | |
beforeEach(() => { | |
jest.resetModules(); | |
}); | |
it('returns url if successful', async () => { | |
const result = [{ secure_url: 'http://cloudinary/img/123.png' }]; | |
global.cloudinary = { | |
openUploadWidget: (params, cb) => { | |
cb(null, result); | |
}, | |
}; | |
const openCloudinaryUploadWidget = require('./openCloudinaryUploadWidget') | |
.default; | |
const response = await openCloudinaryUploadWidget().then(res => res); | |
expect(response).toEqual(result[0].secure_url); | |
}); | |
it('returns error message if failure', async () => { | |
const error = { message: 'Image not found' }; | |
global.cloudinary = { | |
openUploadWidget: (params, cb) => { | |
cb(error, null); | |
}, | |
}; | |
const openCloudinaryUploadWidget = require('./openCloudinaryUploadWidget') | |
.default; | |
const response = await openCloudinaryUploadWidget().catch(err => err); | |
expect(response).toContain(error.message); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment