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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:

Created:

Updated:

Platform:

Replies:

151391 Feb 10,2020 01:21 PM UTC Aug 31,2020 04:38 PM UTC React - EJ 2 5
loading
Tags: General
MARCELLO PALMITESSA
Asked On February 10, 2020 01:21 PM UTC

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

Jesus Arockia Sankaran S [Syncfusion]
Replied On 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 


MARCELLO PALMITESSA
Replied On 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

Banupriya Selvaraj [Syncfusion]
Replied On 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 


Cesar Chavez
Replied On 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

Jesus Arockia Sankaran S [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon