0

I have this logic for temporarily reading and displaying a profile image:

setTempProfileImage(file) {
      if (file) {
        let reader = new FileReader()
        reader.onload = e => {
          this.generalInfo.profileImage = e.target.result
        }
        reader.readAsDataURL(file)
      }
    }

where file is a BLOB object (which for testing is an 'empty' blob object).

But I'm struggling to write a unit test that checks the onload function call and reader.readDataAsURL(file).

I've got this unit test so far:

let file = new Blob(["testing"], { type: "application/pdf" });
wrapper.vm.setTempProfileImage(file)
wrapper.vm.$nextTick()
console.log(wrapper.vm.profileImage)
expect(wrapper.vm.generalInfo.profileImage).toBe(file)

but it simply reads back as 'undefined'

2

1 Answer 1

0

Estus Flask's link answered my question: https://stackoverflow.com/a/61575553/3731501

along with this:

https://zaengle.com/blog/mocking-file-upload-in-vue-with-jest

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.