DEV.co
Open-Source Testing · help-me-mom

ng-mocks

ng-mocks is an Angular testing library that simplifies unit test setup by providing utilities to mock components, directives, pipes, services, and modules. It reduces boilerplate code and integrates with Jasmine and Jest test runners.

Source: GitHub — github.com/help-me-mom/ng-mocks
1.2k
GitHub stars
121
Forks
TypeScript
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryhelp-me-mom/ng-mocks
Ownerhelp-me-mom
Primary languageTypeScript
LicenseMIT — OSI-approved
Stars1.2k
Forks121
Open issues85
Latest releasev14.15.3 (2026-05-27)
Last updated2026-07-08
Sourcehttps://github.com/help-me-mom/ng-mocks

What ng-mocks is

ng-mocks provides MockBuilder for TestBed configuration, MockRender for component fixture creation, and utility functions (ngMocks.change, ngMocks.trigger, MockInstance) for test interactions. It supports Angular 5–22 with Ivy, standalone components, and signals (limited support).

Quickstart

Get the ng-mocks source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/help-me-mom/ng-mocks.gitcd ng-mocks# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Unit testing Angular components with complex dependencies

Rapidly isolate components under test by auto-mocking all dependencies, then selectively keep real modules or services. Reduces TestBed boilerplate by 50–70%.

Test suites with high mock churn

When components frequently change dependencies, ngMocks.defaultMock and MockInstance.scope allow global mock configuration and per-test resets without rewriting specs.

Mixed Jasmine and Jest testing pipelines

Single library supports both runners with auto-spy configuration (ngMocks.autoSpy), eliminating need for runner-specific test utilities.

Implementation considerations

  • Requires TypeScript and Node.js; install via npm or yarn alongside @angular/core and test runner (Jasmine or Jest).
  • Global setup in src/test.ts or src/setup-jest.ts is recommended to configure ngMocks.autoSpy and defaultMock; allows consistent mock behavior across test suite.
  • MockBuilder fluent API has a learning curve; review documentation examples and live CodeSandbox/StackBlitz samples before large-scale rollout.
  • Mocking strategies (shallow, deep, keep certain imports) must be chosen per spec; no one-size-fits-all approach for all test types.
  • CI/CD must run both Jasmine and Jest if testing against both; no built-in runner auto-detection.

When to avoid it — and what to weigh

  • Integration testing is your primary goal — ng-mocks is designed for isolation and mocking; it does not facilitate end-to-end or integration test scenarios. Use it alongside e2e tools, not instead of them.
  • You need performance or security testing — This is a unit testing utility. Performance profiling, load testing, and security scanning require separate tools and frameworks.
  • Your project uses non-standard Angular patterns — ng-mocks assumes standard Angular module structure, TestBed conventions, and reactive forms. Custom DI containers or unusual architectures may require workarounds.
  • Angular versions 4 or earlier — Official support begins at Angular 5. Older versions will not be tested or guaranteed compatible.

License & commercial use

MIT License. Permits commercial and private use, modification, and distribution with no restrictions other than inclusion of license and copyright notice.

MIT is a permissive OSI-approved license. Commercial use is permitted. No license review required for standard commercial software projects. Ensure compliance with MIT attribution requirements in your product documentation or code.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitGood
Assessment confidenceHigh
Security considerations

No security-sensitive operations performed by ng-mocks; it is a testing utility run only in development and CI environments, not in production. Standard npm supply-chain considerations apply. No network calls or data persistence. Review CHANGELOG for any reported vulnerabilities before major version upgrades.

Alternatives to consider

Spectator

Also simplifies Angular testing with TestBed helpers, but focuses on query and trigger utilities more than mocking. Lighter weight for shallow component tests.

@testing-library/angular

Emphasizes user-centric testing and DOM queries; complements rather than replaces mocking. Best used alongside ng-mocks for integration-like unit tests.

Manual TestBed configuration

No external dependency; requires explicit MockModule, MockComponent, MockPipe setup. Increases boilerplate but provides full control and no learning curve.

Software development agency

Build on ng-mocks with DEV.co software developers

ng-mocks reduces TestBed boilerplate and integrates seamlessly with Jasmine and Jest. Evaluate it for your Angular 5–22 projects today.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

ng-mocks FAQ

Does ng-mocks replace Jasmine or Jest?
No. ng-mocks is a companion library for Jasmine or Jest. It provides mocking utilities; the test runner must still be Jasmine or Jest.
Can I use ng-mocks in production code?
No. It is a dev dependency only. Install with npm install --save-dev. Using it in production builds will inflate bundle size with no runtime benefit.
What if a dependency is not mockable with ng-mocks?
Use MockProvider or manual TestBed configuration for edge cases. GitHub discussions and StackOverflow tag ng-mocks can help identify workarounds.
Is there official commercial support?
Unknown. README does not advertise paid support. Community support is available via GitHub issues, discussions, Gitter, and StackOverflow.

Software developers & web developers for hire

Need help beyond evaluating ng-mocks? DEV.co is a software development agency offering software development services and web development for teams of every size. Our software developers and web developers build custom software, web applications, APIs, and open-source testing integrations — and maintain them long-term.

Streamline Your Angular Test Suite

ng-mocks reduces TestBed boilerplate and integrates seamlessly with Jasmine and Jest. Evaluate it for your Angular 5–22 projects today.