Plurrrr

Tue 08 Nov 2022

Mocking a JavaScript Class with Jest, two ways to make it easier

Jest is the most popular automated testing framework for JavaScript. It can be used both on the front end and back end with Node.js. Jest is a feature-rich, batteries included testing framework. Amongst other valuable features, the ability to mock dependencies out of the box is a useful one.

In this post, you will learn about the need for mocking in unit testing and the difference between dependency injection and mocking. You will also get acquainted with mocking in Jest. Furthermore, you will see an example script with two classes and mock the dependent class to test the other class with a full code example using module factory and Jest SpyOn. Let’s get rolling!

Source: Mocking a JavaScript Class with Jest, two ways to make it easier, an article by Geshan Manandhar.

Get Started with Rust: Traits

A trait is a basic language concept for defining shared behavior on types. Traits describe an interface that types can implement.

Rust traits are a sibling of Scala traits and Haskell type classes, as well as a cousin of C++ and Java interfaces.

This article will show you how to use traits in Rust. After reading it, you’ll be able to answer these questions:

  • What is a trait?
  • Why do we use traits in Rust?
  • How to implement and define traits in Rust?
  • What does it mean to derive a trait, and when can we do it?

Source: Traits in Rust, an article by Yevhenii Zelenskyi.

Functional programming from sets and functions

Introductions to functional programming are usually targeted at people who are already accustomed to programming, and they typically present the perks of the paradigm by comparing it to imperative or object-oriented programming. This often leaves the reader with the impression that they have to unlearn practices and concepts they already know to adopt this new paradigm.

In this post I would like to try a different approach, not requiring any programming knowledge, but only the most basic intuition. We will build on high school mathematics, in the form of sets and functions, to provide a learning path to understanding functional programming1.

Source: Functional programming from sets and functions, an article by Marco Perone.

The Takeover (2022)

Framed for murder after uncovering a privacy scandal, an ethical hacker must evade the police while trying to track down the criminals blackmailing her.

In the evening Esme and I watched the Dutch movie The Takeover. It suffers a lot from the typical "hacker" nonsense like slow scrolling source code etc. While I liked to see some parts of Rotterdam, where I have lived for a while in the 90's, I didn't like the movie much and give it a 5 out of 10.