DEV Community

Cover image for How I found a problem with Angular unit testing and decided to fix it myself.
Patricio Ferraggi
Patricio Ferraggi

Posted on • Edited on

How I found a problem with Angular unit testing and decided to fix it myself.

This article was originally posted on my brand new blog The Developer's Dungeon

Hi, my name is Patricio and just like you, I am a software developer. Around a year ago I started working with Angular at my current job as I wanted to be a Fullstack developer again. I worked professionally with Angular.js before and I did a few test projects with Angular but nothing serious.

Coming from a C#/JavaScript background doing TypeScript was not a problem at all. I felt right at home and developed the necessary skills quickly. I had my visual studio code environment ready so I went ahead and started developing using a Test Driven Development approach, as I was so used to in C#.


I created my first tests using Jasmine and Karma as it comes by default with Angular when I first noticed a problem. I had to run “ng test” to run tests in the project, see the output in the console or open a browser and see the results in Karma. If I wanted to run a single test by default, I had to modify the code so it would only run that test.

I was completely astonished, I could not believe that this was how Angular developers were working. The hole testing workflow felt weird, counterproductive and it really slowed me down. Coming from Visual Studio I was so used to having a nice interactive UI where you see all the tests: you run the whole suite or run them individually and get immediate feedback. I needed something similar for Angular to work as efficiently as I do in C#, but I couldn’t find it(Jetbrains ‘s WebStorm had something similar but I was a fan of VS Code and also did not want to buy a product license).

So what did I decide to do? Build my own solution.

Alt Text

This is how my “Angular/Karma Test Explorer” extension came to life.

With the extension you re able to open an Angular project in Visual Studio Code and immediately see all your tests inside the explorer.
You are also able to run the whole suite, or single tests and see the results right away, even see gutter decorations in the file or run the tests directly from the file.

Alt Text

It all started as a personal issue I had and could not find a solution for, but eventually, people started responding to the extension. It started being used at my workplace and other companies, and people showed their appreciation for the project. Users started to request features and even submitted new features which I did not consider important when I started building it.

Alt Text

I was not proficient in Angular or TypeScript (the extension is built on TypeScript so I feel a lot more confident about it now), I would not even consider myself a senior developer, but I saw a problem and took the personal challenge to build something that myself and other people could enjoy.


And this is the takeaway from this article. We as developers create solutions, and no matter the skills you have, you have probably already seen a missing feature, or problem that is not being solved. Don’t wait for someone to fix it for you, go ahead and do it yourself. Help someone else and increase your own skills in the process, I promise you it is going to be a lot of fun.

If you want to check out the project you can find it directly on VSCode or in the Marketplace, if you want to contribute please take a look at the Github repo or if you just want to have a chat with me please feel free to contact me on Twitter. Thank you for taking the time to read this and hopefully it encourages you to keep on start building new products :).

Top comments (7)

Collapse
 
buinauskas profile image
Evaldas Buinauskas

This is great. One question though. Will it support tests written in Jest? We use nx.dev monorepo which ships with Jest as default.

Collapse
 
patferraggi profile image
Patricio Ferraggi

Hi how re you? Is not planned to support other testing library apart from the default for Angular. There is already a test explorer with support with jest using the shared UI I use.
I would try that one 😀

marketplace.visualstudio.com/items...

Collapse
 
buinauskas profile image
Evaldas Buinauskas

Gotcha. Ill try that one out! Thank you.👍

Collapse
 
jbb profile image
Justyna

Hello! Thanks for that extension!
I have a problem to run it
Log: Error log from process: Node.js version v12.22.9 detected.
The Angular CLI requires a minimum Node.js version of v18.19.

I don't even have that version installed, I use only 14 and 18 and even if I set nvm use 18 the log keeps saying the same. Any idea what is missing?

Collapse
 
npd profile image
Neil Deighan

I know this is old .. but found this as I had same issue .. the Test Explorer does not seem to pick up the nvm version of node ... it uses the version that will have been installed on your OS at some point in past i.e. v12.22.9 .. run this to confirm ...

( am on ubuntu, do equiv for your OS)
/usr/bin/node -v

So i upgraded this version of node (which did not affect my nvm setup)

Collapse
 
seangwright profile image
Sean G. Wright

Awesome work! I know the community appreciates your contributions 😁

Collapse
 
patferraggi profile image
Patricio Ferraggi

Thanks for the kind words, I hope that it makes other developers life easier.