Skip to content

Commit

Permalink
Setup crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
poulch committed Jan 3, 2025
1 parent c8927d5 commit 92c6f46
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions testUtils/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "@testing-library/jest-dom";

import { configure } from "@testing-library/react";

jest.mock("@sentry/react");
Expand Down Expand Up @@ -40,9 +41,24 @@ configure({ testIdAttribute: "data-test-id" });
* Fixes (hacks) "TextEncoder is not defined" error which is likely bug in jsdom
*/
import { TextDecoder, TextEncoder } from "util";

global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder as typeof global.TextDecoder;

global.CSS = {
supports: () => false,
} as any;

/**
*
* Fixes (hacks) "crypto is not defined" error which is likely missing implementation in jsdom
*/
import nodeCrypto from "crypto";

global.crypto = {
getRandomValues: function (buffer: any) {
return nodeCrypto.randomFillSync(buffer);
},
subtle: {} as SubtleCrypto,
randomUUID: () => nodeCrypto.randomUUID(),
};

0 comments on commit 92c6f46

Please sign in to comment.