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
8 changes: 8 additions & 0 deletions test/features/DeepStrictAssert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SimpleNested>();
typia.assertEquals(deepStrictAssert(original)('user'));
}

/**
* Tests that deepStrictAssert throws when accessing a non-existent key.
*/
Expand Down