All files / tests TestComponents.tsx

100% Statements 9/9
92.86% Branches 13/14
100% Functions 3/3
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51                    2x           22x   8x 1x 1x   7x                 22x                     8x 8x              
import React from "react";
import { useEffect } from "react";
import { useUpload } from "../src";
 
type Props = {
  method: string;
  url: string;
  headers?: any;
  skipOptionsCb?: () => any;
};
export const BasicTestUpload = ({
  skipOptionsCb,
  method,
  url,
  headers,
}: Props) => {
  let [upload, { error, responseHeaders, progress, done, loading }] = useUpload(
    ({ files }) => {
      if (skipOptionsCb) {
        skipOptionsCb();
        return undefined;
      }
      return {
        method,
        url,
        headers,
        body: files[0],
      };
    }
  );
 
  return (
    <div>
      {responseHeaders ? <div>{responseHeaders.Test}</div> : null}
      {error ? <div>{error}</div> : null}
      {done ? <div>done</div> : null}
      {loading ? <div>loading</div> : null}
      {loading ? `${progress}% progress` : null}
      <input
        type="file"
        aria-label="upload"
        onChange={(e) => {
          Eif (e.target.files) {
            upload({ files: e.target.files });
          }
        }}
      />
    </div>
  );
};