Bunlong / react-papaparse

react-papaparse is the fastest in-browser CSV (or delimited text) parser for React. It is full of useful features such as CSVReader, CSVDownloader, readString, jsonToCSV, readRemoteFile, ... etc.
https://react-papaparse.js.org
MIT License
370 stars 61 forks source link

jest snapshot of CSV Reader is not resolved: Error: Uncaught TypeError: Cannot read property 'addEventListener' of null #76

Closed exaucae closed 3 years ago

exaucae commented 3 years ago

I have this stack trace while taking a snap of a custom file reader. The component is working well except in this snapshot. It throws this error:

console.error Error: Uncaught [TypeError: Cannot read property 'removeEventListener' of null]

Here is my stack

jest@26.6.0 react@17.0.1 typescript@4.2.3

Steps To Reproduce


// component

import React from 'react';
import { CSVReader } from 'react-papaparse';

interface CustomtReaderProps {
  onFileLoaded?: ((data: any, file?: any) => void) | undefined;
}

export const CustomtReader: React.FC<CustomtReaderProps> = (props: CustomtReaderProps) => {

  const { onFileLoaded } = props;
  return (
    <CSVReader
      onFileLoad={onFileLoaded}
      accept='text/csv, .csv'
    >
      <span>{label}</span>
    </CSVReader>
  );

};

// test

describe('OffreTransportReader', () => {

  it('should match snapshot', () => {

    /* FIXME: in the renderer:  Uncaught [TypeError: Cannot read property 'addEventListener' of null]
                                Stacktrace:    Error: Uncaught [TypeError: Cannot read property 'addEventListener' of null]
                                hint: possibly due to the renderer method of  @react-test-render
 */

    const handleFileUploaded = jest.fn().mockImplementation();

    const tree = renderer
      .create(     // <--------------- **_error : TypeError: Cannot read property 'removeEventListener' of null_**
        <CustomtReader
          onFileLoaded={handleFileUploaded}
          label='Chargez votre offre'
        />,
      )
      .toJSON();
    expect(tree).toMatchSnapshot();
  });
});

The current behavior

Error: Uncaught [TypeError: Cannot read property 'addEventListener' of null]

The expected behavior

Test passes

Bunlong commented 3 years ago

@chrys-exaucet I will investigate on it. Thanks!

exaucae commented 3 years ago

@Bunlong, ping.

Bunlong commented 3 years ago

@exaucae It was fixed in latest version 3.16.0, please kindly check. You were added in contributor list. Thanks!

exaucae commented 3 years ago

Ack! Thanks for the feedback. We can safely close this issue.

Bunlong commented 3 years ago

Yes, sure. Thank you so much!