Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ngx-cva-test-suite

dmitry-stepanenko1.4kMIT2.0.1TypeScript support: included

Standardise your custom UI form components with ControlValueAccessor Test Suite

angular unit test, angular simplified tests, jasmine, jest, angular, angular tests, angular test services, angular testing CVA components, control value accessor tests, CVA tests, CVA

readme

ngx-cva-test-suite

Standardise your custom UI form components with ControlValueAccessor Test Suite

ngx-cva-test-suite provides an extensive set of test cases, ensuring your custom controls behave as intended. Package is designed and tested to work properly with both Jest and Jasmine test runners.

It provides various configurations, that allows even the most non-standard components to be properly tested.

Among the main features:

  • ensures the correct amount of calls for the onChange function (incorrect usage may result in extra emissions of valueChanges of formControl)
  • ensures correct triggering of onTouched function (is needed for touched state of the control and updateOn: 'blur' strategy to function properly)
  • ensures that no extra emissions are present when control is disabled
  • checks for control to be resettable using AbstractControl.reset()

In the repository you can also find few simple CVA components, that are configured properly along with ngx-cva-test-suite setup for them.

Installation

npm i ngx-cva-test-suite --save-dev

Simple Usage

import { runValueAccessorTests } from `ngx-cva-test-suite`;

runValueAccessorTests({
    component: ComboboxComponent,
    testModuleMetadata: {
        declarations: [ComboboxComponent],
    },
    supportsOnBlur: true,
    nativeControlSelector: 'input.combobox-input',
    internalValueChangeSetter: (fixture, value) => {
        fixture.componentInstance.setValue(value, true);
    },
    getComponentValue: (fixture) => fixture.componentInstance.value,
});

Full details can be found on GitHub repo's README