DEV Community

Cover image for Angular Testing in 2023 - Past, Present, and Future

Angular Testing in 2023 - Past, Present, and Future

Rainer Hahnekamp on June 06, 2023

Angular 16 has deprecated Karma and introduced Jest in experimental mode. Does that mean we currently have no stable testing framework? Should we s...
Collapse
 
shallfer7 profile image
Charles Fernandes

Great article!

Collapse
 
danywalls profile image
Dany Paredes

Amazing!!!!

Collapse
 
fetis profile image
Sergey Fetiskin

it's 2024 and we're still having the same problem. Jest is extremely slow even with the official builder

Collapse
 
rainerhahnekamp profile image
Rainer Hahnekamp

Yeah, time for an update. You're right except one thing. There is still no official builder...

Collapse
 
fetis profile image
Sergey Fetiskin

I was confused with our setup initially. We use @angular-builders and it's not official one

Collapse
 
ragelter profile image
Rachel Terblanche • Edited

Fantastic article! I'm spear-heading a unit testing implementation endeavour in my current role.

There was a lot of gravitation to try to dive straight into Jest - even though we wouldn't be able to use native Jest today. This article gave me valuable insight into some of the decision factors for consideration.

We're on a pre v16 version today and my evaluation is that considering this, and given that one of our primary objectives is to leverage automation in our build pipelines with coverage enforcement I'm recommending to the team that we stick with Jasmine and Karma on the existing projects and rather start exploring Jest on any green-fields apps where we would be starting with v17 (or latest).

Would be great to get your thoughts on whether this is a pragmatically future-proofed approach. Given your comment about the state of native Jest support in v17, I'm feeling like it is.

Collapse
 
rainerhahnekamp profile image
Rainer Hahnekamp

Hi Rachel, thanks. Given Jest's current status, please stick to Jasmine whenever you can. That applies to green-field apps as well.

If Jest becomes necessary, it should be an officially supported version that uses Angular's build process.

Since the time of this article, Jest didn't really improve.

Collapse
 
antonbakker8 profile image
Marc Antony • Edited

So basically the way you write the tests in typescript does not change? Is that correct? Because frankly I just started with this Jamine/Karma unit testing and was happy enough to get it running in the first place. :-(

I do not have to dump the tests I have made with such effort into the dustbin?

Collapse
 
rainerhahnekamp profile image
Rainer Hahnekamp

Yes, you can continue to write Jasmine tests and in some future version Angular will just switch the runner. For your codebase, nothing should change.

Collapse
 
kashif_7374 profile image
kashif

While running ng test command after setup.
getting this error
dist/test-out/src in the roots[0] option was not found.

Collapse
 
rainerhahnekamp profile image
Rainer Hahnekamp

Hi, in which one of the existing projects did that happen?

Collapse
 
dmedina2150dev profile image
Dajan Medina

Que buen articulo.. Me sirvio para tener un contexto actual del testing en Angular.

Collapse
 
rainerhahnekamp profile image
Rainer Hahnekamp

Gracias, estoy contento de saberlo.

Collapse
 
arnoldm profile image
Arnold Messifet

Hi, thanks for this great article!
Do you know if there's a way to launch tests in a watch mode using angular native jest?

Collapse
 
rainerhahnekamp profile image
Rainer Hahnekamp

No, not yet. I also have to say that the Jest support in Angular 17 didn't really improve compared to v16.

Collapse
 
khylo profile image
khylo

Great article. Any issues running code coverage? So far I'm getting 0%

Collapse
 
rainerhahnekamp profile image
Rainer Hahnekamp

Hi, I mean the goal was not really to measure code coverage. Is there something in particular, you want to know?