Setup Prettier, Typescript and Jest

I build meaningful software by empathising with design, development and business needs. My interests are test automation, functional programming and full-stack web development using NodeJS and other tools.
Search for a command to run...

I build meaningful software by empathising with design, development and business needs. My interests are test automation, functional programming and full-stack web development using NodeJS and other tools.
No comments yet. Be the first to comment.
Get started with Test-Driven Development by building a simple Calculator API in a modern, server-side, framework - Fastify.
Why a health route? I want to begin with the end in mind. When our API is deployed in a cloud environment, the automated, cloud deployment will need a way to know that our API has started correctly. That is the purpose of the GET /health route. I hav...
Being able to safely refactor code is one of the greatest benefits of writing tests. The goal of refactoring is to improve code design e.g. style, design patterns, performance. Let's take an example from the previous route handler which has already b...

Marginal gains ⚙️ The 2020 Summer Olympic Games were held in Tokyo between 23 July and 8 August. The enduring motto of the Olympics is “Faster, Higher, Stronger”. From 1908 to 2003 the British cycling team won only 1 gold medal at the Olympics. This ...

This is a scenario that took some time to understand. I could see errors in the browser but everything on the server seemed to be configured correctly. The problem was, that when a request was made by the browser, the server handling the request made...

Florida and Minnesota each developed their Statewide Automated Child Welfare Information System (SACWIS). In Florida, system development started in 1990 and was estimated to take 8 years and cost $32 million. As Johnson spoke in 2002, Florida had spe...

Why a health route? I want to begin with the end in mind. When our API is deployed in a cloud environment, the automated, cloud deployment will need a way to know that our API has started correctly. That is the purpose of the GET /health route. I hav...

The beginning is a very good place to start and we begin by setting up our project. You might want to skip this if you're familiar with setting up a project with Jest and Typescript.
I have opened a Github pull request that shows all the code changes which I'll explain below.
I prefer to use Visual Studio Code as my IDE and I recommend installing the Prettier extension to format code. This keeps our code tidy and easier to read.
Typescript supercharges JavaScript with type checking. Type checks limit bugs by looking over our shoulders for mistakes like strings instead of numbers. More advanced uses of types can even help document our code. If you've ever wanted to phone a friend for some help while coding in JavaScript then give Typescript a try.
Jesting is another way of saying joking. And another word for joking is mocking. I guess that's why this testing and mocking library is called Jesting.
No place like 127.0.0.1 🏡
Jest doesn't yet work with Typescript so we'll need a plugin to help translate our Typescript code for Jest. I've used the ts-jest plugin for this.
To get started I need to install the packages and run the tests. So in a terminal window at the root of the project, I have run -
npm installnpm testJest reports "No tests found, exiting with code 1". Don't panic. In Test-Driven Development we have to get used to our tests not working at first. When we add the correct code and the tests pass, we prove that the code works. Don't trust tests that can't fail.
That's all the setup steps. The next step is a code walkthrough.
If I've missed anything that you would like explained, please let me know in the comments