Sitemap
Ace D Baugh

Ace D Baugh

I am a Fine Art Photographer and Fine Code Programmer. I shoot Sony Raw and am a Full Stack Web Developer

Using Jest

2 min readAug 10, 2022
Press enter or click to view image in full size
Photo by Rachel on Unsplash

Jest is a JavaScript test framework that allows you to test your code before you make it go live for users to use. It is fully compatible with libraries and other frameworks like Node.js, React, Angular, and more. Jest was created as part of the Facebook Open Source Community and it is used by many companies, including Facebook, Twitter, Instagram, and Spotify (Jest). The main reasons to use Jest are that it is easy to install, it runs fast, and tests and errors are easy to read and understand (2018). Jest can handle both Test Driven Development (TDD) and Behavior Driven Developement (BDD).

TDD is writing code, testing that code, and refactoring it so it works. Jest allows you to do just that by creating tests that take code in and runs it against what you expect to happen and gives you a very clear report as to what the outcome was (2021). Then if the test fails, you, as the programmer, can refactor or fix the code to work. Though it can happen, that too much testing is done, it usually allows programmers the ability to test every bit of code before moving on. Luckily Jest is fast enough to run multiple tests at once.

BDD is slightly different from TDD in that your focus on the behavior of the code is at the forefront. Dan North, one of the founders of BDD stated that it was designed to address issues that came up from TDD, it is not easy to grasp without understanding TDD first (2022). BDD makes the programmer think from a user point of view more often and using Jest can help you create tests that do just that by focusing on the functionality of code.

Get Ace D Baugh’s stories in your inbox

Join Medium for free to get updates from this writer.

In summary, unit testing with either way you choose to be driven is useful and most importantly done at every stage of your coding journey. Think of what you want the program to accomplish, then create each part and test it along the way. You may spend more time testing, but less time getting stuck and each piece of code will make more sense to you and others reading it.

References:

BDD: Learn About Behavior Driven Development. Agile Alliance |. (2022, February 6). Retrieved August 10, 2022, from https://www.agilealliance.org/glossary/bdd

Jest. Jest RSS. (n.d.). Retrieved August 10, 2022, from https://jestjs.io/

(2018). YouTube. Retrieved August 10, 2022, from https://youtu.be/cAKYQpTC7MA.

What is Test Driven Development (TDD)? Agile Alliance |. (2021, March 4). Retrieved August 10, 2022, from https://www.agilealliance.org/glossary/tdd

--

--

Ace D Baugh
Ace D Baugh

Written by Ace D Baugh

I am a Fine Art Photographer and Fine Code Programmer. I shoot Sony Raw and am a Full Stack Web Developer