diff --git a/webapp/components/ContributionForm/ContributionForm.spec.js b/webapp/components/ContributionForm/ContributionForm.spec.js index e553118c7..df95d82f9 100644 --- a/webapp/components/ContributionForm/ContributionForm.spec.js +++ b/webapp/components/ContributionForm/ContributionForm.spec.js @@ -233,10 +233,13 @@ describe('ContributionForm.vue', () => { }) it('supports adding a teaser image', async () => { + const spy = jest.spyOn(FileReader.prototype, 'readAsDataURL').mockImplementation(() => {}) expectedParams.variables.imageUpload = imageUpload wrapper.find(ImageUploader).vm.$emit('addHeroImage', imageUpload) await wrapper.find('form').trigger('submit') expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams)) + expect(spy).toHaveBeenCalledWith(imageUpload) + spy.mockReset() }) it('content is valid with just a link', async () => { diff --git a/webapp/components/ContributionForm/ContributionForm.vue b/webapp/components/ContributionForm/ContributionForm.vue index a4f76f3d2..cc0680524 100644 --- a/webapp/components/ContributionForm/ContributionForm.vue +++ b/webapp/components/ContributionForm/ContributionForm.vue @@ -194,8 +194,15 @@ export default { this.$refs.contributionForm.update('content', value) }, addHeroImage(file) { - this.imageUpload = file - this.formData.image = file ? URL.createObjectURL(file) : null + this.formData.image = null + if (file) { + const reader = new FileReader() + reader.onload = ({ target }) => { + this.formData.image = target.result + } + this.imageUpload = file + reader.readAsDataURL(file) + } }, addImageAspectRatio(aspectRatio) { this.formData.imageAspectRatio = aspectRatio diff --git a/webapp/components/PostTeaser/PostTeaser.spec.js b/webapp/components/PostTeaser/PostTeaser.spec.js index cfa8fb5f7..1e90cd1cf 100644 --- a/webapp/components/PostTeaser/PostTeaser.spec.js +++ b/webapp/components/PostTeaser/PostTeaser.spec.js @@ -66,7 +66,7 @@ describe('PostTeaser', () => { } it('has no validation errors', () => { - const spy = jest.spyOn(global.console, 'error'); + const spy = jest.spyOn(global.console, 'error') Wrapper() expect(spy).not.toBeCalled() spy.mockReset()