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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

TypeError: Cannot read property 'getRandomValues' of undefined for Unit test

Thread ID:

Created:

Updated:

Platform:

Replies:

142070 Jan 14,2019 05:46 AM UTC Jan 23,2019 05:44 AM UTC React - EJ 2 5
loading
Tags: Common
Mohammad
Asked On January 14, 2019 05:46 AM UTC

i have created component for Syncfusion Column Chart, and tried to unit test my code using JEST (react-test-renderer), got error.
TypeError: Cannot read property 'getRandomValues' of undefined

    TypeError: Cannot read property 'getRandomValues' of undefined

      31 | describe('<Column />', () => {
      32 |     test('Column changes the class when hovered', () => {
    > 33 |         const component = renderer.create(
         |                                    ^
      34 |             <Column data={data1} chartProp={chartProp1} />,
      35 |             );
      36 |             const tree = component.toJSON();

      at m (node_modules/@syncfusion/ej2-base/dist/ej2-base.umd.min.js:10:2061)
      at e.r [as constructor] (node_modules/@syncfusion/ej2-base/dist/ej2-base.umd.min.js:10:72492)
      at e.o [as constructor] (node_modules/@syncfusion/ej2-charts/dist/ej2-charts.umd.min.js:10:137363)
      at new e (node_modules/@syncfusion/ej2-react-charts/dist/ej2-react-charts.umd.min.js:20:8204)
      at constructClassInstance (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:4833:18)
      at updateClassComponent (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6685:5)
      at beginWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7540:16)
      at performUnitOfWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:10358:12)
      at workLoop (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:10390:24)
      at renderRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:10476:7)
      at performWorkOnRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11342:7)
      at performWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11254:7)
      at performSyncWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11228:3)
      at requestWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11097:5)
      at scheduleWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:10907:5)
      at scheduleRootUpdate (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11494:3)
      at updateContainerAtExpirationTime (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11522:10)
      at updateContainer (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11533:10)
      at Object.create (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12079:5)
      at Object.create (src/lib/charts/column/Column.test.jsx:33:36)

Jayakumar Duraisamy [Syncfusion]
Replied On January 17, 2019 12:21 PM UTC

Hi Mohammad, 
We need to mock all functionalities of window and others related to DOM in JEST for properly running the unit test cases in it. We will analyze this further and get back to you with more details within 2 working days on January 21, 2019. 
Regards, 
Jayakumar D 


Jayakumar Duraisamy [Syncfusion]
Replied On January 17, 2019 02:52 PM UTC

Hi Mohammad, 
Please ignore the previous update. 
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. 
However, we will analyze the possibilities of using all the functionalities used in our components in testing environment and get back to you with more details within 2 working days on January 21, 2019. 
Regards, 
Jayakumar D 


Mohammad
Replied On January 22, 2019 08:37 AM UTC

Hi Mohammad, 
Please ignore the previous update. 
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. 
However, we will analyze the possibilities of using all the functionalities used in our components in testing environment and get back to you with more details within 2 working days on January 21, 2019. 
Regards, 
Jayakumar D 


Still waiting for update

Can you please provide update?

Mohammad
Replied On January 22, 2019 09:02 AM UTC

Hi Mohammad, 
Please ignore the previous update. 
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. 
However, we will analyze the possibilities of using all the functionalities used in our components in testing environment and get back to you with more details within 2 working days on January 21, 2019. 
Regards, 
Jayakumar D 


Still waiting for update

Can you please provide update?

Found following solution, adding following lines in test file
Object.defineProperty(global.self, 'crypto', {
value: {
getRandomValues: (arr) => crypto.randomBytes(arr.length)
}
});

It works


Jayakumar Duraisamy [Syncfusion]
Replied On January 23, 2019 05:44 AM UTC

Hi Mohammad, 
Thanks for your update. 
We are glad to hear that your error was resolved. Please let us know, if you need any further assistance. 
Regards, 
Jayakumar D 


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

;