Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Angular
  3. ng-mocks

ng-mocks

MITTypeScriptv14.18.1

Angular testing library for mocking components, directives, pipes, services and facilitating TestBed setup.

Visit WebsiteGitHubGitHub
1.2k stars119 forks0 contributors

What is ng-mocks?

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.

Target Audience

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.

Value Proposition

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.

Overview

Angular testing library for mocking components, directives, pipes, services and facilitating TestBed setup

Use Cases

Best For

  • Reducing boilerplate in Angular unit tests by mocking components, directives, pipes, services, modules, and tokens with utilities like MockBuilder.
  • Testing Angular components that use OnPush change detection or lifecycle hooks, as MockRender respects these Angular features.
  • Simulating events like keyboard shortcuts in tests using ngMocks.trigger for interactive component testing.
  • Writing integration tests for Angular applications with complex dependency trees by mocking entire modules or providers.
  • Configuring global mock behaviors across test suites to avoid copy-pasting code, using ngMocks.defaultMock.
  • Automatically spying on methods in mock declarations and providers to simplify assertion and verification in tests.

Not Ideal For

  • Projects using testing frameworks not supported by ng-mocks, such as Mocha or Karma without Jasmine/Jest integration
  • Teams that prioritize minimal dependencies and prefer using only Angular's native testing utilities
  • Applications heavily relying on Angular's defer feature, as ng-mocks currently lacks support for it

Pros & Cons

Pros

Comprehensive Mocking

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.

Boilerplate Reduction

Utilities like MockBuilder and MockRender minimize repetitive test setup code, making tests cleaner and more maintainable, as demonstrated in the example spec.

Automatic Spying

Methods in mock declarations are automatically spied on, simplifying assertion and verification without manual spy setup, a feature enabled via ngMocks.autoSpy.

Lifecycle Integration

MockRender respects Angular lifecycle hooks and OnPush change detection, ensuring realistic component testing, which is crucial for integration tests.

Cons

Missing Defer Support

The compatibility table explicitly shows no support for Angular's defer feature, limiting usability in modern applications adopting this capability.

Additional Dependency

Introduces an external library that can complicate project setup and maintenance, especially for teams aiming to keep dependencies minimal.

API Complexity

The variety of utilities like MockBuilder, MockRender, and MockInstance has a steep learning curve, potentially slowing down onboarding for new users.

Frequently Asked Questions

Quick Stats

Stars1,159
Forks119
Contributors0
Open Issues15
Last commit1 day ago
CreatedSince 2018

Tags

#service#unit-testing#pipe#standalone-components#directive#mocking#testing#ivy#mock#testbed#jasmine#test#angular#signals#provider#component#jest

Links & Resources

Website

Included in

Angular10.0k
Auto-fetched 23 hours ago

Related Projects

mswmsw

The industry standard for API mocking in JavaScript.

Stars18,261
Forks629
Last commit1 day ago
stryker-jsstryker-js

Mutation testing for JavaScript and friends

Stars3,172
Forks294
Last commit2 days ago
spectatorspectator

🦊 🚀 A Powerful Tool to Simplify Your Angular Tests

Stars2,189
Forks186
Last commit6 months ago
ArchUnitTSArchUnitTS

ArchUnitTS is an architecture testing library. Specify and ensure architecture rules in your TypeScript app. Easy setup and pipeline integration.

Stars501
Forks14
Last commit1 day ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub