I’ve been writing a bunch of jest tests recently for libraries that use the underlying window.crypto
methods like getRandomValues()
and window.crypto.subtle
key management methods. One problem I run into is that the window.crypto
object isn’t available, so I need to shim it.
To use the window.crypto
methods, you will need Node 15+. You can set the window.crypto
by importing the crypto
package and setting it on the global:
const crypto = require('crypto').webcrypto; // Shims the crypto property onto global global.crypto = crypto;
I really loathe creating mock functions for missing libraries in Node because they can lead to faulty positives on tests; I really appreciate webcrypto
being available!
JavaScript Promise API
While synchronous code is easier to follow and debug, async is generally better for performance and flexibility. Why “hold up the show” when you can trigger numerous requests at once and then handle them when each is ready? Promises are becoming a big part of the JavaScript world…
9 Mind-Blowing Canvas Demos
The
<canvas>
element has been a revelation for the visual experts among our ranks. Canvas provides the means for incredible and efficient animations with the added bonus of no Flash; these developers can flash their awesome JavaScript skills instead. Here are nine unbelievable canvas demos that…
Optimize Your Links For Print Using CSS — Show The URL
When moving around from page to page in your trusty browser, you get the benefit of hovering over links and viewing the link’s target URL in the status bar. When it comes to page printouts, however, this obviously isn’t an option. Most website printouts…
Spyjax: Ajax For Evil Using Dojo
The idea of Spyjax is nothing new. In pasts posts I’ve covered how you can spy on your user’s history with both MooTools and jQuery. Today we’ll cover how to check user history using the Dojo Toolkit. The HTML For the sake of this…
Source link