ngx-cva-test-suite is an Angular testing utility designed to streamline and standardize the process of unit testing custom form components that implement `ControlValueAccessor` (CVA). Currently at version 2.0.1, this library provides a comprehensive set of pre-defined test cases, ensuring that custom controls correctly handle essential CVA behaviors such as `onChange` and `onTouched` calls, disabled states, and `reset()` functionality, which are common sources of errors in CVA implementations. It is compatible with both Jest and Jasmine test runners and offers various configuration options to accommodate diverse component structures. Releases for this library typically align with major Angular version updates, with patch releases addressing bug fixes. Its key differentiator lies in its robust, pre-built test suite that reduces boilerplate and potential oversight when developing complex, custom form controls, aiming for extensive unit test coverage.
npm install ngx-cva-test-suiteVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up `ngx-cva-test-suite` for an Angular component implementing `ControlValueAccessor` and basic validation, showing the component definition alongside its test suite invocation.
Upgrade your Angular project to version 12 or newer, or downgrade `ngx-cva-test-suite` to a v1.x.x release compatible with your current Angular version.
Carefully review your component's template and TypeScript logic to ensure that `nativeControlSelector` targets the correct input element, `internalValueChangeSetter` properly simulates a value change within the component, and `getComponentValue` correctly extracts the component's internal value. Refer to the library's GitHub examples for guidance.
Ensure `testModuleMetadata.declarations` includes the component being tested and any its direct dependencies. Also, add necessary `imports` (e.g., `ReactiveFormsModule` or `FormsModule` if your CVA interacts with forms directly) and `providers` (e.g., for `NG_VALUE_ACCESSOR`, `NG_VALIDATORS`).
Set `supportsOnBlur: true` if your component explicitly handles blur events to trigger `onTouched`. Ensure `nativeControlSelector` is also correctly specified when `supportsOnBlur` is true to allow the test suite to simulate blur events on the correct element.
Run `npm install ngx-cva-test-suite --save-dev` or `yarn add ngx-cva-test-suite --dev`. Ensure the import statement `import { runValueAccessorTests } from 'ngx-cva-test-suite';` is correct.Ensure you are using `import { runValueAccessorTests } from 'ngx-cva-test-suite';` for ESM environments, which is standard for modern Angular projects. Avoid `const { runValueAccessorTests } = require('ngx-cva-test-suite');`.Update your Angular project's dependencies to Angular v12.0.0 or higher, or downgrade `ngx-cva-test-suite` to a v1.x.x version that supports your current Angular version.