-
-
Notifications
You must be signed in to change notification settings - Fork 2
No failures for nested errors in aggregate errors #24
Description
For my unit test (with tap) I'm looking to catch and describe the details of a thrown AggregateError. I've been running into an issue where it seems like the errors on the aggregate are being totally ignored — it compares the message but not the contents of the error. So tests which match the name but fail to match content errors end up passing!
This is reflected in tcompare's same() behavior, which has this for errors:
: !this.isError() && b instanceof Error
? false
: this.isError() &&
((b.message && b.message !== a.message) ||
(b.name && b.name !== a.name))
? falseAnd in match():
: this.isError() &&
((pattern.message &&
!new Match(obj.message, {
expect: pattern.message,
}).test()) ||
(pattern.name &&
!new Match(obj.name, {
expect: pattern.name,
}).test()))
? falseI thought this would be handled by deeper matching (i.e. foreign property errors on A doesn't match errors on B), but I'm not sure where that's written in the code.
This might speak to a larger issue on custom error objects in general? E.g, attaching other kinds of data to a custom Error-extending object — it would be important to both catch that the thrown error has the right constructor/instanceof and carries the right exposed data. I'm not sure if any of that, nor aggregate errors, are covered by tcompare right now.
Just in case I'm making a dumb mistake, here's my unit test code:
t.throws(
() => Template.validateDescription({
annotation: `my cool template`,
content: 'this is not a function',
}),
new AggregateError([
new TypeError(`Expected description.content to be a function`),
], `Errors validating template "my cool template" description`));Making a change to the message of the AggregateError it's comparing against causes this to fail, as it should. But changing the message of the TypeError should also make it fail (since the message doesn't match), and it doesn't — the error still passes. Even removing the TypeError or adding totally unrelated errors still doesn't cause a fail.