Angular testing library for mocking components, directives, pipes, services and facilitating TestBed setup.
ng-mocks is a comprehensive testing library for Angular applications that simplifies mocking components, directives, pipes, services, modules, and tokens. It reduces boilerplate in tests and provides a clean interface to access declarations, making unit and integration testing more efficient and maintainable. The library aligns with Angular's testing patterns to enable developers to write clean, focused tests without manual mock creation overhead.
Angular developers writing unit or integration tests who need to mock dependencies like components, services, or modules, particularly those using Jasmine or Jest test runners. It's also suitable for teams maintaining large Angular codebases across versions 5 to 22, including Ivy, standalone components, and signals.
Developers choose ng-mocks over alternatives because it offers a robust, flexible API that automatically spies on methods, respects Angular lifecycle hooks and OnPush change detection, and reduces repetitive test setup code with utilities like MockBuilder and MockRender. Its wide compatibility with Angular versions 5-22 and support for modern features like standalone components and signals provide a future-proof testing solution.
Angular testing library for mocking components, directives, pipes, services and facilitating TestBed setup
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports mocking of all Angular entities including components, directives, pipes, services, modules, and tokens, as highlighted in the key features, eliminating the need for manual mock creation.
Utilities like MockBuilder and MockRender minimize repetitive test setup code, making tests cleaner and more maintainable, as demonstrated in the example spec.
Methods in mock declarations are automatically spied on, simplifying assertion and verification without manual spy setup, a feature enabled via ngMocks.autoSpy.
MockRender respects Angular lifecycle hooks and OnPush change detection, ensuring realistic component testing, which is crucial for integration tests.
The compatibility table explicitly shows no support for Angular's defer feature, limiting usability in modern applications adopting this capability.
Introduces an external library that can complicate project setup and maintenance, especially for teams aiming to keep dependencies minimal.
The variety of utilities like MockBuilder, MockRender, and MockInstance has a steep learning curve, potentially slowing down onboarding for new users.