Introduction to testing in JavaScript

Imagine Hans Solo staring at you and saying don’t test me without ever opening his mouth
Star Wars gif taken from tenor

Transitioning from Ruby to JavaScript during the Flatiron Software Engineering program was initially overwhelming. However, I overcame most challenges by learning JavaScript’s test language. As a new programmer, I completely understand that learning to test seems impossible and easily dismissible at first, but testing is an invaluable skill. This blog will introduce some benefits and types of testing that exist. Specifically, this blog presents unit testing, integration testing, and end-end testing. While learning to test can feel like a massive undertaking, testing makes all the difference when learning a programming language.

Testing code, either while learning a new language or developing an application, is super helpful. Anyone who has taken a computer programming course, from a Bootcamp like Flatiron or collegiately, has experienced the benefits of testing first hand. While learning, testing helps to break down complex topics and identify explicit deficiencies we have. For example, rendering objects to a window with vanilla JS is an incredibly involved process. Without a pair programmer by your side, it can take hours to debug the simplest mistakes. Testing can get us that time back!

Hit meme by Nicholas Fraser

Okay, fine, I won’t lie to you and say that creating a test is easy or that testing has significant benefits from the start-up. However, identifying specific issues to address, time regained from debugging, and reusability of the test makes the time investment of learning to test insignificant.

As developers, testing ensures that our code is functioning as intended and is resilient to edge cases. Nothing is worse than spending 56+ hours on a project only for it to break while you are presenting to a class, or even worse, your boss. Through this program, I learned that successful software engineers are not geniuses that breathe binary; instead, they work smarter and maximize their time. As you know and build programs, creating and running tests allows the computer to do the hard parts for you. I Can’t think of anything smarter than that.

When I first started learning to test, I discovered a broad topic that can quickly become overwhelming. I expected to What’s important to keep in mind when you begin to study test suites is not to have all the answers, but the passion and patience to the purpose of each test. To save you from having the same experience, I will briefly introduce three critical testing methods- Unit, Integration, and End-to-end testing.

nit testing
The unit in Unit test refers to the smallest aspects of a program, such as a function or states/props’ existence. Since the magnitude of functions varies, so too does will the test. For example, testing the length of a store is relatively simple. We can say something like:

describe(‘restaurants input’, () => {

expect(store.getState().BlogViewStats.length).to.equal(0)

}

However, testing that a submit handler updates the store upon submission is incredibly involved and more akin to Integration testing.

ntegration testing
Integration tests are those that primarily deal with the communication aspect of the application. Are handlers returning data? Is that data passed to all of the relevant components? Is there persistence?

nd-to-end testing
End-to-end testing is the most active type of testing I see. End-to-end testing is a laborious method. These tests typically center around user stories. Can a user render a photo in the assigned location when they click this button? While these tests are challenging and take time to make, their reusability and teaching opportunities make the End-to-end test worth building.

Learning to build test is excellent for learning any programming language, ensuring your code’s quality, and boosting productivity. As you develop any programming language skills, it will become increasingly important and more comfortable for you to digest and build test. A great way to make your test knowledge as you learn a language is to read all available spec and testing suites of a lab. It is not important to understand every single line rather, the test’s purpose. Once you can discern what a test asks for in layman terms and expecting in code format, you will truly feel transported to a whole new world.

I am a graduated environmental studies researcher, who began a computer science boot-camp. I will be blogging solutions to what I struggle with most.

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