diff --git a/projects/cdk/karma.conf.js b/projects/cdk/karma.conf.js index c743656e3c38..d5fc3979853c 100644 --- a/projects/cdk/karma.conf.js +++ b/projects/cdk/karma.conf.js @@ -1,4 +1,4 @@ -const base = require('../../karma.conf'); +const base = require('../../karma.config'); module.exports = function (config) { base(config); diff --git a/projects/cdk/observables/index.ts b/projects/cdk/observables/index.ts index b34049d79e61..1317c2d6847f 100644 --- a/projects/cdk/observables/index.ts +++ b/projects/cdk/observables/index.ts @@ -3,6 +3,7 @@ export * from './focus-visible-observable'; export * from './is-alive'; export * from './items-query-list-observable'; export * from './mouse-drag-finish-from'; +export * from './must-be-present'; export * from './pressed-observable'; export * from './prevent-default'; export * from './replay-control-value-changes'; diff --git a/projects/cdk/observables/must-be-present.ts b/projects/cdk/observables/must-be-present.ts new file mode 100644 index 000000000000..1e1b17dc65a4 --- /dev/null +++ b/projects/cdk/observables/must-be-present.ts @@ -0,0 +1,13 @@ +import {isPresent} from '@taiga-ui/cdk/utils/miscellaneous'; +import {OperatorFunction} from 'rxjs'; +import {map} from 'rxjs/operators'; + +export function mustBePresent(): OperatorFunction { + return map(value => { + if (!isPresent(value)) { + throw new Error('Value must present'); + } + + return value; + }); +} diff --git a/projects/cdk/observables/test/must-be-present.spec.ts b/projects/cdk/observables/test/must-be-present.spec.ts new file mode 100644 index 000000000000..b79673af01ba --- /dev/null +++ b/projects/cdk/observables/test/must-be-present.spec.ts @@ -0,0 +1,72 @@ +import {fakeAsync, tick} from '@angular/core/testing'; +import {mustBePresent} from '@taiga-ui/cdk/observables/must-be-present'; +import {Subject} from 'rxjs'; +import {first} from 'rxjs/operators'; + +describe('mustBePresent operator function', () => { + it('not throws on NaN', fakeAsync(() => { + const stream = new Subject(); + + stream.pipe(first(), mustBePresent()).subscribe(); + + expect(() => { + stream.next(NaN); + tick(); + }).not.toThrow(); + })); + + it('not throws on 0', fakeAsync(() => { + const stream = new Subject(); + + stream.pipe(first(), mustBePresent()).subscribe(); + + expect(() => { + stream.next(0); + tick(); + }).not.toThrow(); + })); + + it('not throws on false', fakeAsync(() => { + const stream = new Subject(); + + stream.pipe(first(), mustBePresent()).subscribe(); + + expect(() => { + stream.next(false); + tick(); + }).not.toThrow(); + })); + + it('not throws on empty string', fakeAsync(() => { + const stream = new Subject(); + + stream.pipe(first(), mustBePresent()).subscribe(); + + expect(() => { + stream.next(''); + tick(); + }).not.toThrow(); + })); + + it('throws on undefined', fakeAsync(() => { + const stream = new Subject(); + + stream.pipe(first(), mustBePresent()).subscribe(); + + expect(() => { + stream.next(undefined); + tick(); + }).toThrow(); + })); + + it('throws on null', fakeAsync(() => { + const stream = new Subject(); + + stream.pipe(first(), mustBePresent()).subscribe(); + + expect(() => { + stream.next(null); + tick(); + }).toThrow(); + })); +}); diff --git a/projects/core/package.json b/projects/core/package.json index 505a09f8df81..48579005f9c7 100644 --- a/projects/core/package.json +++ b/projects/core/package.json @@ -22,7 +22,7 @@ "@angular/forms": ">=6.0.0", "@angular/platform-browser": ">=6.0.0", "@angular/router": ">=6.0.0", - "@tinkoff/ng-event-filters": ">=1.0.0", + "@tinkoff/ng-event-plugins": ">=1.0.1", "@tinkoff/ng-polymorpheus": ">=2.0.0", "rxjs": ">=6.0.0" }