3

I am trying to create a valid Blob object for one of my test cases in react jest. I am using new Blob to create a Blob but getting an empty Blob object like Blob {}.

const myBlob = new Blob([`/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/
2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/`], { type: 'image/jpeg' });

console.log(myBlob);

What I think there is a native javascript code missing in jest to create a new Blob. Is there any other way to achieve it. Please let me know. I am new to it.

Thanks in advance.

Johannes Klauß
  • 10,068
  • 15
  • 65
  • 117
Shubham
  • 1,655
  • 3
  • 14
  • 31
  • 1
    This answer might help you: https://stackoverflow.com/a/16245768/735226 Basically you need a byte array, you cannot just create a Blob from base64. Or you use the fetch approach like here, which is far simpler: https://stackoverflow.com/a/36183085/735226 – Johannes Klauß Sep 29 '20 at 09:02
  • 3
    Also to add: Jest is just a library that runs on a specific platform, so every javascript feature that this platform (i.e. nodejs or a browser) implemented is available. It has nothing to do with jest. – Johannes Klauß Sep 29 '20 at 09:04

0 Answers0