Open Bug 1480075 Opened 3 years ago Updated 1 year ago

Should Assert.rejects reject or report a test error when the exception is incorrect

Categories

(Testing :: General, enhancement, P3)

enhancement

Tracking

(Not tracked)

ASSIGNED

People

(Reporter: jdescottes, Assigned: jdescottes)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

Currently, if the exception thrown by the code tested by Assert.rejects is not the expected one, the exception is just bubbled up and shows up in the test logs as 

FAIL Uncaught exception - ${Stringified version of the error}

If the error message is very different from the expected one, or worst if the error is an object (FAIL Uncaught exception [Object object]), it is difficult to realize that the code is already being checked in an Assert.rejects.

It would be nice if we could have an additional failure report, that logs the failure message provided by the caller.

The relevant code is at https://searchfox.org/mozilla-central/rev/196560b95f191b48ff7cba7c2ba9237bba6b5b6a/testing/modules/Assert.jsm#425-428

We could either report and reject, or only report.
Mark, any reason why we just reject the error at the moment?
Flags: needinfo?(standard8)
Since we have unit tests checking that the original exception is still thrown, I suppose doing both is the only viable option.

https://treeherder.mozilla.org/#/jobs?repo=try&revision=636c396124b4bf1a0e7b3bc09e05b5801dc3732b
This definitely seems a reasonable thing to do. Mike is probably a bit more of an expert in this area though.
Flags: needinfo?(standard8) → needinfo?(mdeboer)
I agree with Mark, I'd be happy with this change.
Flags: needinfo?(mdeboer)
Priority: -- → P3
Blocks: 1676736
Attachment #9187264 - Attachment description: Bug 1480075 - Report a meaningful failure wheen Assert.reject catches an incorrect exception → Bug 1480075 - Report a meaningful failure when Assert.reject catches an incorrect exception
Assignee: nobody → jdescottes
Attachment #9187264 - Attachment description: Bug 1480075 - Report a meaningful failure when Assert.reject catches an incorrect exception → Bug 1480075 - Report a meaningful failure when Assert.rejects catches an incorrect exception
Status: NEW → ASSIGNED
You need to log in before you can comment on or make changes to this bug.