Personal note
This is a redacted version of an internal document I prepared for a client. It is based off the most recent revision and i...
For further actions, you may consider blocking this person and/or reporting abuse
Thanks, Esteban!
Too few resources on Angular testing even though testability is a core concern for the Angular framework.
The state of Angular Testing as of today is: Non-exinstent documentation, obsolete books that focus around the big problem if 1+1 equals 2, incomplete tutorials and posts by "professionals" who in their spare time are fathers, tech enthusiasts and pet lovers, youtubers advertising themselves as experts and mvp's that the only thing they achive is to break the 100 subscriber barrier, non-native english speakers with horrible accent who record their so called 'tutorials' by using their phone's microphone and/or with incomprehensible accents. Books are written and advertised as professional series, and they leave testing for the very end, instead of being at the very beginning after the creation of the new project. Of course, they only cover the basics such as checking if a component has been created or if a fake service returns the expected results. That's it. A trained cat can check if an h1 tag contains 'Hello world'. Not a single attempt to go deeper, as if the subject must be avoided like the plague. At the end of each day, I wonder whether to burn the .spec.ts files and do everything manually with dubious results, spend endless hours of researching in sources here and there, or to look somewhere else, maybe React, even though I have my doubts that the situation over there is any better. And above all I also have 'experts' telling me not to test the private methods. Well, it's my f***ing projects and I will test whatever I want.
I would offer you a listing of my articles on testing Angular applications, but I'm afraid that I'm a father, a tech enthusiast, and a Microsoft MVP, so you might not be interested 😄
Yourself and Net Basal are the only ones I have discovered so far to be of any interest. As a continuation to my response, since I'm fussy, picky and perfectionist, I'm looking for the 0.5% of knowledge which the 99.5% don't seem to care about - this is the reason for my initial reply and I dedicate it to the vast majority. So, throw me anything you've got! Hope I'm making sence! Greetings from 39°38'N / 19°55'E.
I recommend the book Testing Angular Applications by Jesse Palmer et. al.
Here are my Angular testing articles:
The next one is 70% done.
Lars,
Super awesome, thanks a million!
Have a great weekend!
Regards,
John
Thanks a lot!!
Nice article! Helped me a lot!! Testing definitely makes software better, this is a great resource. Every software developer must understant its importance, it's one of best practices. Greetings from Colombia.
I need to help on writing testcase for this functions.
private element: any;
@Input() id: string;
constructor(private el: ElementRef) {
this.element = el.nativeElement;
}
ngOnInit(): void {
if (!this.id) {
return;
}
this.element.addEventListener("click", (el: any) => {
if (el.target.className === "tfb-modal-background") {
this.close();
}
});
}
I need to help on writing testcase for this functions.
private element: any;
@Input() id: string;
constructor(private el: ElementRef) {
this.element = el.nativeElement;
}
ngOnInit(): void {
if (!this.id) {
return;
}
this.element.addEventListener("click", (el: any) => {
if (el.target.className === "tfb-modal-background") {
this.close();
}
});
}
Hey, try separating your large function into smaller ones that can be tested in isolation.
If you have several simple pipes that depend on each other, try combining them in a custom pipe and test that with a mock observable.
So for RxJS, you can:
My general rule of thumb is that a function should hardly ever have more than two or three tests. When a function requires more than that, you can probably break it down into two or more.
Nice article but i hope this gets updated with the latest api
Thanks for this very nice article on testing!
Is it possible to use Jasmine Marbles to test services instead of mocking it using a spy?
You have a typo in one of your examples: changeCouner
Hey what if input variable is coming from another component where we have retrieved it from backend api service.
Do we still follow same approach as mentioned by you