Uncategorized

How do I test Signals (signal, computed, effect)?

Signals as lightweight “reactive primitive” will shape the future of Angular applications. At the time of this writing, signal() and computed() are stable, and effect() is in developer preview. Developer preview doesn’t mean we have an unstable feature but that the Angular team can introduce breaking changes within a major version. The feature is stable; …

How do I test Signals (signal, computed, effect)? Read More »

How do I test using the RouterTestingHarness?

Historically, creating a test involving the routing context without mocking it has been challenging. This is mainly due to less-than-optimal documentation on RouterTestingModule or provideLocationMock. In the meantime, some community projects, especially Spectacular from Lars Nielsen, have helped us out. Spectacular by ngworkers | Spectacular This article explains how to use the RouterTestingHarness to write sound …

How do I test using the RouterTestingHarness? Read More »

How do I test code using inject()?

This article discusses testing Angular code, which uses the inject function for dependency injection. If you are more of a visual learner, here’s a video for you: https://medium.com/media/e1f4a05a89392e4ab835000ea9d9e832/href Why inject()? The inject function, introduced in Angular 14, is an alternative to the constructor-based dependency injection. inject has the following advantages: 1. Standardization of Decorators Decorators have …

How do I test code using inject()? Read More »

How do I test and mock Standalone Components?

If you prefer the kind of tests that minimize mocking as much as possible, you will be pretty happy with Standalone Components. Gone are the struggles of meticulously picking dependencies from NgModules for your Component under test. Standalone Components come self-contained. Add them to your TestingModule’s imports property, and all their “visual elements” — Components, Directives, Pipes, and …

How do I test and mock Standalone Components? Read More »