Angular Unit Tests with the inject() function

preview_player
Показать описание
In this video, I discuss approaches for unit tests in Angular. I focus on those kinds of tests where the class under test is instantiated manually and gets its dependencies not via the constructor but via the inject function, which was introduced in Angular 14.

Рекомендации по теме
Комментарии
Автор

Hi Rainer, thx for picking up the topic!
It seems the inject() is rarely used at the moment and also the docs are lacking information.
I recently had issues testing pipes which injects services via inject() method. I managed to successfully test them by using a WrapperComponent which injects the pipe, so I could avoid hacking around, but I would like to see easier ways in the future.
All the best and keep up the good work!

ShiftedBit
Автор

Thanks a lot for your content!. I have seen many of your videos and I have learned a lot.

cgardev
Автор

HI Rainer,
Thx for that smart solution.
Does it still work with Angular 17 ? I noticed your sample application is using anguler 15.

theboringcode
Автор

Why would one use the inject-function when the 'old' way is clearer in specifying the dependencies and much simpler to test?

Автор

The documentation for this is truly embarrassing, they state not to use the old class based guard and to use the new inject function, but how to unit test? God knows...

roytouw