Practical Unit Testing

Image by 3D Animation Production Company from Pixabay

Updated Version

There’s an updated version of this article here:


We have a Map<number,any> like this:

const map1 = new Map();

If we delete the entry with index 2 the remaining indexes are [3,4] . We want a function that calculates this result and we want unit tests for it.


First lets document and implement our function:

Notice that the way we documented our function makes it easy to unit test it.

Here’s the unit test. Note that we are testing edge conditions:

Related Concepts

Brought to You By Firefly Semantics




Founder of Firefly Semantics Corporation

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Javascript Project — Flatiron School

Clones in node_modules got you down? Dedupe your filesystem

ParaState Crowdloan: Geminis Network takes part in Polkadot Slot Auction #14-#18

Been using this app lately and I like it

JavaScript topics for interview preparation

How to use apollo as a state container

The Most Critical JavaScript (JS) Trends to Watch in 2021

Using APIs in React

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ole Ersoy

Ole Ersoy

Founder of Firefly Semantics Corporation

More from Medium

Partitioning Project Variations in Git Branches

Gift Card System using .NetCore, RedisJSON and ReactJs

Jest: Test Driven Development