vendredi 27 novembre 2020

Jest and RTL to test a input type image file

Is there a way to use jest and RTL to input an image file, most examples i am seeing online is mocking a file by by using a string; however, I am trying to upload an image file which will then be compressed and then convert into base64 and finally display it on the DOM.

  function imageFileHandler(file) {
    setDisplay(file);
    toBase64(file).then((data) => setSelectedFile(data));
  }

  function imageCompressor(event) {
    const file = event.target.files[0];
    console.log(typeof file)
    const options = {
      maxSizeMB: 0.05,
      maxWidthOrHeight: 700,
      useWebWorker: true,
    };
    imageCompression(file, options)
      .then((compressedFile) => {
        console.log(compressedFile);
        imageFileHandler(compressedFile);
      })
      .catch(() => setErrorForm('unable to convert image file'));
  }

Aucun commentaire:

Enregistrer un commentaire