shallow-render is an Angular testing utility designed to simplify unit testing of components by providing shallow rendering and easy mocking capabilities. It aims to reduce the boilerplate often associated with Angular's native TestBed. The current stable version is 20.0.0, which aligns with Angular v20. The library generally releases new major versions in lockstep with Angular's major releases, ensuring compatibility. Its key differentiator is a more streamlined API that allows developers to focus specifically on the component under test without needing to declare all its deep dependencies or resort to `NO_ERRORS_SCHEMA`, simplifying test setup and maintenance. The project is actively seeking additional maintainers, indicating a potential future shift in its maintenance model, though it remains updated with new Angular versions by the current maintainer.
npm install shallow-renderVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up `shallow-render` for an Angular component, render it with specific inputs, assert its rendered DOM content using selectors, and verify event outputs when a user interaction occurs.
Consult the `shallow-render` release notes and the Angular version support table for compatibility. Upgrade `shallow-render` to the matching major version for your Angular project.
Monitor the project's GitHub repository for updates on maintenance status. Consider contributing if stable long-term support is critical for your project.
Supplement shallow unit tests with integration tests using `TestBed` (without `NO_ERRORS_SCHEMA`) or end-to-end tests for critical user flows and complex component interactions.
Ensure all direct dependencies of the component under test are either included in the NgModule provided to `Shallow`, explicitly mocked using `shallow.mock()` or `shallow.dontMock()`, or that the component itself is standalone and its imports are handled.
Ensure that your `shallow-render` version matches your Angular major version (e.g., `shallow-render@20` for `@angular/core@20.x`). Upgrade `shallow-render` using `npm install shallow-render@latest` or `ng update shallow-render` if available.
When asserting outputs, ensure you are accessing the correct output property from the `outputs` object returned by `shallow.render()` (e.g., `outputs.myOutput.emit`). `shallow-render` typically provides a mock `emit` automatically.