Skip to content

Commit af30db9

Browse files
chore: improve assertion with expected path (#4474)
Co-authored-by: Bailey Pearson <[email protected]>
1 parent f176de4 commit af30db9

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

test/tools/unified-spec-runner/match.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,16 @@ export function resultCheck(
262262
return;
263263
}
264264

265-
if (typeof actual !== 'object') {
266-
expect.fail('Expected actual value to be an object');
267-
}
265+
expect(
266+
actual,
267+
`Expected actual (${inspect(actual)}) to be an ${Array.isArray(expected) ? 'array' : 'object'} at: ${path.join('')}`
268+
).to.satisfy(actual =>
269+
Array.isArray(expected) ? Array.isArray(actual) : typeof actual === 'object'
270+
);
268271

269272
const expectedEntries = Object.entries(expected);
270273

271274
if (Array.isArray(expected)) {
272-
if (!Array.isArray(actual)) {
273-
expect.fail(
274-
`expected value at ${path.join('.')} to be an array, but received ${inspect(actual)}`
275-
);
276-
}
277275
for (const [index, value] of expectedEntries) {
278276
path.push(`[${index}]`);
279277
checkNestedDocuments(index, value, checkExtraKeys);

test/unit/tools/unified_spec_runner.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('Unified Spec Runner', function () {
135135

136136
expect(() => resultCheckSpy(actual, expected, entitiesMap, [])).to.throw(
137137
AssertionError,
138-
/Expected actual value to be an object/
138+
/to be an object/
139139
);
140140
});
141141
});

0 commit comments

Comments
 (0)