<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: TypeError: cryptoObj.getRandomValues is not a function; unrelated error when using jest in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/TypeError-cryptoObj-getRandomValues-is-not-a-function-unrelated/m-p/1967396#M30598</link>
    <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp;，&lt;/P&gt;
&lt;P&gt;Please review the content in the following thread, hope they can help you resolve the problem.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;A href="https://github.com/microsoft/powerbi-client-react/issues/21" target="_self"&gt;When importing PowerBIEmbed in jest tests, fails right away with Cannot read property 'getRandomValues' of undefined&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.syncfusion.com/forums/142070/typeerror-cannot-read-property-getrandomvalues-of-undefined-for-unit-test" target="_self"&gt;&lt;STRONG&gt;TypeError: Cannot read property 'getRandomValues' of undefined for Unit test&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
    <pubDate>Tue, 20 Jul 2021 06:26:04 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-07-20T06:26:04Z</dc:date>
    <item>
      <title>TypeError: cryptoObj.getRandomValues is not a function; unrelated error when using jest</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/TypeError-cryptoObj-getRandomValues-is-not-a-function-unrelated/m-p/1963294#M30561</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have a project where I've used powerbi-client in some part of my application. When I try to test some other components (which doesn't use powerbi-client) using testing-library/react and run npm test I get&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;TypeError: cryptoObj.getRandomValues is not a function&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;error. Before I was getting&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;crypto_nonexistent&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;error like mentioned in&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/2980" target="_blank" rel="noopener"&gt;this issue&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;and managed to fix this error by adding crypto to jest globals using craco.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my jest config&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="126031307-cfe65639-2d21-4d17-a3a6-9165bf660165" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/555174iF135728E8ECDE950/image-size/large?v=v2&amp;amp;px=999" role="button" title="126031307-cfe65639-2d21-4d17-a3a6-9165bf660165" alt="126031307-cfe65639-2d21-4d17-a3a6-9165bf660165" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Error stack trace:&lt;/P&gt;&lt;PRE&gt;TypeError: cryptoObj.getRandomValues is not a function

  12 |
  13 | import React, { useState, useEffect } from 'react';
&amp;gt; 14 | import { models, Embed, service } from 'powerbi-client';
     | ^
  15 | import { PowerBIEmbed } from 'powerbi-client-react';
  16 | import { appServices } from 'common/services';
  17 | import { useAccount, useMsal } from '@azure/msal-react';

  at Function.WindowPostMessageProxy.createRandomString (node_modules/powerbi-client/dist/webpack:/powerbi-client/node_modules/window-post-message-proxy/dist/windowPostMessageProxy.js:125:1)
  at new WindowPostMessageProxy (node_modules/powerbi-client/dist/webpack:/powerbi-client/node_modules/window-post-message-proxy/dist/windowPostMessageProxy.js:77:1)
  at wpmpFactory (node_modules/powerbi-client/dist/webpack:/powerbi-client/src/factories.ts:27:10)
  at new Service (node_modules/powerbi-client/dist/webpack:/powerbi-client/src/service.ts:160:17)
  at Object../src/powerbi-client.ts (node_modules/powerbi-client/dist/webpack:/powerbi-client/src/powerbi-client.ts:64:15)
  at __webpack_require__ (node_modules/powerbi-client/dist/webpack:/powerbi-client/webpack/bootstrap:19:1)
  at node_modules/powerbi-client/dist/webpack:/powerbi-client/webpack/bootstrap:83:1
  at node_modules/powerbi-client/dist/powerbi.js:100:10
  at webpackUniversalModuleDefinition (node_modules/powerbi-client/dist/webpack:/powerbi-client/webpack/universalModuleDefinition:3:1)
  at Object.&amp;lt;anonymous&amp;gt; (node_modules/powerbi-client/dist/webpack:/powerbi-client/webpack/universalModuleDefinition:10:2)
  at Object.&amp;lt;anonymous&amp;gt; (src/analytics/PowerBi/powerbi.tsx:14:1)
  at Object.&amp;lt;anonymous&amp;gt; (src/analytics/PowerBi/index.tsx:5:1)
  at Object.&amp;lt;anonymous&amp;gt; (src/main/App/App.tsx:18:1)
  at Object.&amp;lt;anonymous&amp;gt; (src/home/OfficesExplore/offices-explore.tsx:12:1)
  at Object.&amp;lt;anonymous&amp;gt; (src/home/OfficesExplore/index.tsx:1:1)
  at Object.&amp;lt;anonymous&amp;gt; (src/home/__tests__/offices-explore.test.tsx:3:1)&lt;/PRE&gt;&lt;H3&gt;Expected Behavior&lt;/H3&gt;&lt;P&gt;Npm test command should work without any problems because the component that I am testing doesn't rely on powerbi-client.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jul 2021 09:15:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/TypeError-cryptoObj-getRandomValues-is-not-a-function-unrelated/m-p/1963294#M30561</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-07-17T09:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: TypeError: cryptoObj.getRandomValues is not a function; unrelated error when using jest</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/TypeError-cryptoObj-getRandomValues-is-not-a-function-unrelated/m-p/1967396#M30598</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp;，&lt;/P&gt;
&lt;P&gt;Please review the content in the following thread, hope they can help you resolve the problem.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;A href="https://github.com/microsoft/powerbi-client-react/issues/21" target="_self"&gt;When importing PowerBIEmbed in jest tests, fails right away with Cannot read property 'getRandomValues' of undefined&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.syncfusion.com/forums/142070/typeerror-cannot-read-property-getrandomvalues-of-undefined-for-unit-test" target="_self"&gt;&lt;STRONG&gt;TypeError: Cannot read property 'getRandomValues' of undefined for Unit test&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 06:26:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/TypeError-cryptoObj-getRandomValues-is-not-a-function-unrelated/m-p/1967396#M30598</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-07-20T06:26:04Z</dc:date>
    </item>
  </channel>
</rss>

