-
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.
Answered by
idleberg
Mar 4, 2022
Replies: 2 comments 1 reply
-
Try
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Turns out I need Node 17+ to get the browser-compatible |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
idleberg
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out I need Node 17+ to get the browser-compatible
crypto
API