We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Jest unit test fails with Error: Uncaught [TypeError: Cannot read property 'id' of undefined]

Hi,
running this simple test with Jest on a React component containing the DateRangePicker, I get the error Uncaught [TypeError: Cannot read property 'id' of undefined]
This is the test code:

import React from 'react';
import ReactDOM from 'react-dom';

Object.defineProperty(window, 'crypto', {
  value: {
    getRandomValues: arr => jest.fn().mockImplementation(arr => 0)
  },
});

it("renders without crashing", () => {
  const div = document.createElement("div");
  ReactDOM.render(<MyComponent />,
    div
  );
  ReactDOM.unmountComponentAtNode(div);
});


Please find attached the full error stack trace.

How can be fixed this issue?


Attachment: jesterror.txt_4af641b4.zip

5 Replies

JA Jesus Arockia Sankaran S Syncfusion Team February 11, 2020 01:50 PM UTC

Hi Marcello, 
 
Thanks for contacting Syncfusion support. 
 
Since JEST does not have all window functions, we need to mock all functionalities of window and others related to DOM if that are not implemented in the JEST. Please refer the mocking options provided in JEST documentation.   
 
 
So currently our react component will not support JEST. We suggest you to use jasmine environment for performing unit test for EJ2 react components.  
 
Regards, 
Jesus Arockia Sankaran S 



MP MARCELLO PALMITESSA February 11, 2020 02:04 PM UTC

Hi,
At least may you help by listing all the function that need to be mocked in Jest?
Honestly I don't understand the choice to not support Jest, since it's the official test tool for React applications, and one of the most used globally.

Best regards
Marcello


BS Banupriya Selvaraj Syncfusion Team February 17, 2020 02:30 AM UTC

Hi Marcello,  

Sorry for the delay update.  

Query 1: At least may you help by listing all the function that need to be mocked in Jest?  
  
Please refer the below links to know more about the functions that need to be mocked in Jest.  
   
Query 2: Honestly I don't understand the choice to not support Jest, since it's the official test tool for React applications, and one of the most used globally.  

We have considered the reported issue of Jest unit test fails on our react components and logged a task for it. This issue will be fixed in any one of our upcoming releases. You can track the this using the below feedback link.  

Please let us know if you have any concerns.  

Regards,  
Banupriya 



CC Cesar Chavez July 24, 2020 02:51 PM UTC

Hi guys i think what marcello meant is to list the bunch of functions that we need to mock
not how to do it

if you can come up with that list, and some examples that would be great thanks!!


Best Regards


JA Jesus Arockia Sankaran S Syncfusion Team August 31, 2020 04:38 PM UTC

Hi Cesar, 

Sorry for the inconvenience. 

We would want to inform you that we have to mock possibly all of the Windows and DOM functionalities and we have already logged a bug report as “Jest unit test fails in React components”. You can keep track of the bug from the feedback portal below. 


The fix will be available in any of our upcoming release  and if you have any more specification you can add it as a comment in the portal.    
 
Regards, 
Jesus Arockia Sankaran S 


Loader.
Up arrow icon