Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

633
Views
How to test file upload and file content in TypeScript Unit Test

I am trying to test an input tag but I want to test the content of the uploaded file. here is the code -

<input
  data-testid="file-input"
  type="file"
  accept=".csv, .tsv"
  onChange={(event) => {
    if (event.target.files !== null) {
      setCsvFile(event.target.files[0]);
      let reader = new FileReader();
      var content: string | ArrayBuffer | null | undefined;

      reader.onload = function () {
        content = reader.result;
        console.log(reader.result);
      };

      reader.onerror = function () {
        console.log(reader.error);
      };

      reader.readAsText(event.target.files[0]);
    }
  }}
/>;

How can I unit test what is being read by FileReader on file upload?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!