ngx-cva-test-suite
v2.0.1
Published
Standardise your custom UI form components with ControlValueAccessor Test Suite
Downloads
3,479
Maintainers
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 ofvalueChanges
of formControl) - ensures correct triggering of
onTouched
function (is needed fortouched
state of the control andupdateOn: '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