diff --git a/src/functions/DeepStrictAssert.ts b/src/functions/DeepStrictAssert.ts index 4fb8d92..3034f66 100644 --- a/src/functions/DeepStrictAssert.ts +++ b/src/functions/DeepStrictAssert.ts @@ -33,7 +33,7 @@ export const deepStrictAssert = if (input instanceof Array) { const elements = input.map((element) => { if (first in element) { - if (typeof element[first] === 'object' && element[first] !== null) { + if (typeof element[first] === 'object' && element[first] !== null && rest.length > 0) { return { [first]: traverse(element[first], rest) }; } @@ -46,7 +46,7 @@ export const deepStrictAssert = return elements; } else { if (first in input) { - if (typeof input[first] === 'object' && input[first] !== null) { + if (typeof input[first] === 'object' && input[first] !== null && rest.length > 0) { return { [first]: traverse(input[first], rest) }; } return { [first]: input[first] }; diff --git a/test/features/DeepStrictAssert.ts b/test/features/DeepStrictAssert.ts index fc9229d..649c1f3 100644 --- a/test/features/DeepStrictAssert.ts +++ b/test/features/DeepStrictAssert.ts @@ -105,6 +105,14 @@ export function test_functions_deepStrictAssert_accesses_nested_object_property( typia.assertEquals(deepStrictAssert(original)('user.name')); } +/** + * Tests that deepStrictAssert can access a top-level key whose value is a plain object. + */ +export function test_functions_deepStrictAssert_accesses_top_level_object_property() { + const original = typia.random(); + typia.assertEquals(deepStrictAssert(original)('user')); +} + /** * Tests that deepStrictAssert throws when accessing a non-existent key. */