Skip to content

Commit c49b272

Browse files
committed
test: add more types to test
1 parent 41768b0 commit c49b272

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

packages/core/src/shared/utilities/collectionUtils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ export function assign<T extends Record<any, any>, U extends Partial<T>>(data: T
305305
* @param depth
306306
* @param omitKeys Omit properties matching these names (at any depth).
307307
* @param replacement Replacement for object whose fields extend beyond `depth`, and properties matching `omitKeys`.
308-
* @param maxStringLength truncates string values that exceed this threshold.
308+
* @param maxStringLength truncates string values that exceed this threshold (includes values in nested arrays)
309309
*/
310310
export function partialClone(
311311
obj: any,
@@ -318,8 +318,10 @@ export function partialClone(
318318
): any {
319319
// Base case: If input is not an object or has no children, return it.
320320
if (typeof obj !== 'object' || obj === null || 0 === Object.getOwnPropertyNames(obj).length) {
321-
const maxLength = options?.maxStringLength
322-
return typeof obj === 'string' && maxLength !== undefined ? truncate(obj, maxLength, '...') : obj
321+
if (typeof obj === 'string' && options?.maxStringLength) {
322+
return truncate(obj, options?.maxStringLength, '...')
323+
}
324+
return obj
323325
}
324326

325327
// Create a new object of the same type as the input object.

packages/core/src/test/shared/utilities/collectionUtils.test.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -770,26 +770,36 @@ describe('CollectionUtils', async function () {
770770

771771
it('truncates properties by maxLength', function () {
772772
const testObj = {
773-
a: '1',
774-
b: '11',
775-
c: '11111',
776-
d: {
777-
e: {
778-
a: '11111',
779-
b: '11',
773+
strValue: '1',
774+
boolValue: true,
775+
longString: '11111',
776+
nestedObj: {
777+
nestedObjAgain: {
778+
longNestedStr: '11111',
779+
shortNestedStr: '11',
780780
},
781781
},
782+
nestedObj2: {
783+
functionValue: (_: unknown) => {},
784+
},
785+
nestedObj3: {
786+
myArray: ['1', '11111', '1'],
787+
},
788+
objInArray: [{ shortString: '11', longString: '11111' }],
782789
}
783790
assert.deepStrictEqual(partialClone(testObj, 5, [], { maxStringLength: 2 }), {
784-
a: '1',
785-
b: '11',
786-
c: '11...',
787-
d: {
788-
e: {
789-
a: '11...',
790-
b: '11',
791+
...testObj,
792+
longString: '11...',
793+
nestedObj: {
794+
nestedObjAgain: {
795+
longNestedStr: '11...',
796+
shortNestedStr: '11',
791797
},
792798
},
799+
nestedObj3: {
800+
myArray: ['1', '11...', '1'],
801+
},
802+
objInArray: [{ shortString: '11', longString: '11...' }],
793803
})
794804
})
795805
})

0 commit comments

Comments
 (0)