jest snapshot of CSV Reader is not resolved: Error: Uncaught TypeError: Cannot read property 'addEventListener' of null
See original GitHub issueI 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:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ack! Thanks for the feedback. We can safely close this issue.
@exaucae It was fixed in latest version 3.16.0, please kindly check. You were added in contributor list. Thanks!