Practical Unit Testing

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



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