ngx-cva-test-suite
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

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

Package Sidebar

Install

npm i ngx-cva-test-suite

Weekly Downloads

55

Version

2.0.1

License

MIT

Unpacked Size

258 kB

Total Files

25

Last publish

Collaborators

  • dmitry-stepanenko