question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
exaucaecommented, Jun 4, 2021

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

1reaction
Bunlongcommented, Jun 4, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'addEventListener' of null - Stack Overflow
On those pages where the function cannot find the id, I receive a "Cannot read property 'addEventListener' of null " error and none...
Read more >
cannot read property 'addeventlistener' of null jest - You.com
Bunlong/react-papaparsejest snapshot of CSV Reader is not resolved: Error: Uncaught TypeError: Cannot read property 'addEventListener' of null#76.
Read more >
TypeError: Cannot read property 'addEventListener' of null jest ...
Answers related to “TypeError: Cannot read property 'addEventListener' of null jest”. Uncaught TypeError: Cannot read property 'addEventListener' of ...
Read more >
Cannot read property `property` of null in 'react-test-renderer ...
Recently, I ran into some problems while attempting to snapshot test my React code. TypeError: Cannot read property 'focus' of null.
Read more >
Node.js v19.3.0 Documentation
No require , exports , or module.exports; No __filename or __dirname; No Addon Loading; No ... encoding]); Errors while reading; An example counting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found