diff --git a/npm/ng-packs/packages/core/src/lib/tests/array-utils.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/array-utils.spec.ts new file mode 100644 index 0000000000..3ccc91461c --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/tests/array-utils.spec.ts @@ -0,0 +1,17 @@ +import { pushValueTo } from '../utils/array-utils'; + +describe('Array Utils', () => { + describe('#pushValueTo', () => { + test.each` + source | target | expected + ${[]} | ${[0, 1, 2, 3]} | ${[0, 1, 2, 3]} + ${[3]} | ${[0, 1, 2]} | ${[0, 1, 2, 3]} + ${[2, 3]} | ${[0, 1]} | ${[0, 1, 2, 3]} + ${[1, 2, 3]} | ${[0]} | ${[0, 1, 2, 3]} + ${[0, 1, 2, 3]} | ${[]} | ${[0, 1, 2, 3]} + `('should push $source to $target when called in forEach', ({ source, target, expected }) => { + source.forEach(pushValueTo(target)); + expect(target).toEqual(expected); + }); + }); +}); diff --git a/npm/ng-packs/packages/core/src/lib/utils/array-utils.ts b/npm/ng-packs/packages/core/src/lib/utils/array-utils.ts new file mode 100644 index 0000000000..d2d74105b3 --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/utils/array-utils.ts @@ -0,0 +1,6 @@ +export function pushValueTo(array: T[]) { + return (element: T) => { + array.push(element); + return array; + }; +} diff --git a/npm/ng-packs/packages/core/src/lib/utils/index.ts b/npm/ng-packs/packages/core/src/lib/utils/index.ts index b75fef8efe..ce89b4dddb 100644 --- a/npm/ng-packs/packages/core/src/lib/utils/index.ts +++ b/npm/ng-packs/packages/core/src/lib/utils/index.ts @@ -1,3 +1,4 @@ +export * from './array-utils'; export * from './common-utils'; export * from './factory-utils'; export * from './form-utils';