diff --git a/projects/cdk/observables/control-value.ts b/projects/cdk/observables/control-value.ts index 4dc605ba8c43..9017ff5d331a 100644 --- a/projects/cdk/observables/control-value.ts +++ b/projects/cdk/observables/control-value.ts @@ -1,5 +1,4 @@ import {AbstractControl, AbstractControlDirective} from '@angular/forms'; -import {TuiValueChangesException} from '@taiga-ui/cdk/exceptions'; import {Observable} from 'rxjs'; import {startWith} from 'rxjs/operators'; @@ -9,11 +8,8 @@ import {startWith} from 'rxjs/operators'; export function tuiControlValue( control: AbstractControl | AbstractControlDirective, ): Observable { - return new Observable(subscriber => { - if (!control.valueChanges) { - throw new TuiValueChangesException(); - } - - return control.valueChanges.pipe(startWith(control.value)).subscribe(subscriber); - }); + return new Observable( + subscriber => + control?.valueChanges?.pipe(startWith(control.value)).subscribe(subscriber), + ); } diff --git a/projects/cdk/observables/test/control-value.spec.ts b/projects/cdk/observables/test/control-value.spec.ts index 5b5da1f22278..75cda1d3293e 100644 --- a/projects/cdk/observables/test/control-value.spec.ts +++ b/projects/cdk/observables/test/control-value.spec.ts @@ -1,7 +1,6 @@ import {fakeAsync} from '@angular/core/testing'; -import {AbstractControl, FormControl} from '@angular/forms'; +import {FormControl} from '@angular/forms'; import {tuiControlValue} from '@taiga-ui/cdk'; -import {tuiSwitchNgDevMode} from '@taiga-ui/testing'; import {skip} from 'rxjs/operators'; describe('tuiControlValue', () => { @@ -30,38 +29,4 @@ describe('tuiControlValue', () => { expect(actual).toBe('test'); })); - - describe('dev mode', () => { - beforeEach(() => tuiSwitchNgDevMode(true)); - - it('throws an error if there is no valueChanges', fakeAsync(() => { - let actual = ''; - - tuiControlValue({} as AbstractControl).subscribe({ - next: () => {}, - error: (err: unknown) => { - actual = (err as Error).message; - }, - }); - - expect(actual).toBe('Control does not have valueChanges'); - })); - - afterEach(() => tuiSwitchNgDevMode(false)); - }); - - describe('production mode', () => { - it('throws an error if there is no valueChanges', fakeAsync(() => { - let actual = ''; - - tuiControlValue({} as AbstractControl).subscribe({ - next: () => {}, - error: (err: unknown) => { - actual = (err as Error).message; - }, - }); - - expect(actual).toBe(''); - })); - }); });