-
Does anybody here have experience on how to run tests that involve the Crypto API? In a React project, I have a function creating a hash from a string. const encoder = new TextEncoder();
const data = encoder.encode(message);
const hash = await crypto.subtle.digest("SHA-256", data); However, when I try and test this function using Vitest, I'm running into a type error:
I already added the following to my tests: import crypto from "node:crypto";
globalThis.crypto = crypto; Without it, it already fails at Can anyone please help? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Try
|
Beta Was this translation helpful? Give feedback.
-
Turns out I need Node 17+ to get the browser-compatible |
Beta Was this translation helpful? Give feedback.
Turns out I need Node 17+ to get the browser-compatible
crypto
API