What are your Angular testing best practices?
Unit Testing in a New Angular Project - Best Library Recommendations?
Best practices for testing with Angular
Any good tools or practices to debug and track randomly failed angular unit tests
Videos
Writing tests that are checking the rendered HTML are a real pain and the worst productivity killer I've ever encountered! I mean tests with TestBed.createComponent and nativeElement.querySelector and the like.
Already the test setup is a pain, because you have to list all the modules even the ones that are not directly used but needed by other components. The compiler doesn't necessarily show this kind of error, because sometimes this will only lead to runtime errors. If a used component gets a new dependency, you have to change the test ...
Using TestBed is also incredibly slow. fixture.detectChanges, tick and the likes are not productivity boosters either.
Locating and interacting with elements is sometimes a pain, too. For example I've tested a view with expandable elements. First I selected the buttons to expand and then called click on them. But it worked only for a single one (no matter wich one). Maybe I made a mistake, but the details are not the point, the point is that it is so hard to write this kind of test.
So, how do you test your Angular application? What do you test at what level? What approach do you use on the different testing layers (e. g. unit tests without HTML, cypress, snapshots ...)?
Hey r/Angular2!
I'm starting a brand new Angular project and I'm planning to implement unit tests from the very beginning. I'm looking for recommendations on the best unit testing library to use in this context.
I'm aware that Angular CLI sets up Jasmine and Karma by default, but I'm open to exploring other options if they offer significant advantages. I'm particularly interested in:
-
Ease of use and setup: I want a library that's relatively straightforward to integrate and use within an Angular project.
-
Maintainability and readability: Tests should be easy to write, understand, and maintain over time.
-
Integration with Angular features: Seamless compatibility with Angular's dependency injection, components, services, and other core features is crucial.
-
Performance: Fast test execution is important for a smooth development workflow.
-
Mocking capabilities: Effective mocking of dependencies is essential for isolating units of code.
-
Community support and documentation: A strong community and comprehensive documentation are valuable resources.
I've heard about Jest being a popular alternative to Karma/Jasmine, and I'm curious about its benefits in an Angular environment. Has anyone had experience using Jest with Angular and can share their thoughts?
Also, what are your thoughts on:
-
Using standalone components and the impact of the testing strategy.
-
Testing best practices for signal based applications.
-
Any tools to help with test coverage reporting outside of the standard Karma output.
-
Any libraries that help with testing angular forms and http requests. Are there any other libraries or tools that I should consider? Any advice or insights you can offer would be greatly appreciated!
Thanks in advance!