vendredi 3 janvier 2020

Testing functions containing Promise and FileReader() in Jest

Currently trying to test the following function:

const readFileAsync = (file, use = false) =>
  new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.onload = () => {
      resolve(reader.result);
    };
    reader.onerror = reject;
    if (use) reader.readAsDataURL(file);
    else reader.readAsArrayBuffer(file);
  });

export default readFileAsync;

But having massive issues with the FileReader aspect in regards to mocking. Any advice?

Aucun commentaire:

Enregistrer un commentaire