Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/functions/DeepStrictAssert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
}

Expand All @@ -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] };
Expand Down
12 changes: 12 additions & 0 deletions test/features/DeepStrictAssert.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ok } from 'assert';
import typia, { tags } from 'typia';
import { deepStrictAssert } from '../../src';

Expand Down Expand Up @@ -130,3 +131,14 @@ export function test_functions_deepStrictAssert_accesses_multiple_nested_array_p
typia.assertEquals(resultD);
typia.assertEquals(resultE);
}

/**
* Tests that deepStrictAssert can access a non-leaf object key without crashing.
* This verifies the fix for GitHub issue #19.
*/
export function test_functions_deepStrictAssert_accesses_non_leaf_object_key() {
const data = { user: { name: 'Alice', age: 30 } };
const result = deepStrictAssert(data)('user');
ok(result.user.name === 'Alice');
ok(result.user.age === 30);
}