Skip to content

chore: improve assertion with expected path #4474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 19, 2025
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
14 changes: 6 additions & 8 deletions test/tools/unified-spec-runner/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,16 @@ export function resultCheck(
return;
}

if (typeof actual !== 'object') {
expect.fail('Expected actual value to be an object');
}
expect(
actual,
`Expected actual (${inspect(actual)}) to be an ${Array.isArray(expected) ? 'array' : 'object'} at: ${path.join('')}`
).to.satisfy(actual =>
Array.isArray(expected) ? Array.isArray(actual) : typeof actual === 'object'
);

const expectedEntries = Object.entries(expected);

if (Array.isArray(expected)) {
if (!Array.isArray(actual)) {
expect.fail(
`expected value at ${path.join('.')} to be an array, but received ${inspect(actual)}`
);
}
for (const [index, value] of expectedEntries) {
path.push(`[${index}]`);
checkNestedDocuments(index, value, checkExtraKeys);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/tools/unified_spec_runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('Unified Spec Runner', function () {

expect(() => resultCheckSpy(actual, expected, entitiesMap, [])).to.throw(
AssertionError,
/Expected actual value to be an object/
/to be an object/
);
});
});
Expand Down