-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Runner#fail should work with Error-like objects #1677
Comments
sort of. comment(s) in #1678 |
@igorraush @mochajs/mocha Igor, thanks for the PR and bringing this to our/my attention. As a quick bit of background, we're filtering PR #1678 changes the API, thus is a "breaking change". But whether or not anything will actually break is a concern:
Coming at this from another angle--and I'd love some thoughts on this from others--what if we actually stopped trying to modify the stack altogether?
Instead of setting If an @igorraush Once the dust settles and if we decide to move forward here, please squash & rebase onto branch |
@boneskull As for JetBrains's reporter, it doesn't expect |
@boneskull What do you think about separately merging the changes which actually fix this issue (i.e. modified checks in |
Closing as this was fixed via #1758 and went out with 2.3.0 :) The check is now: if (!(err instanceof Error || err && typeof err.message == 'string')) { Thanks! |
@danielstjules I've been using my fork and didn't notice :) Thanks. |
Problem
The check
if (!(err instanceof Error))
at https://github.com/mochajs/mocha/blob/master/lib/runner.js#L205 causes a problem when writing tests for an Angular app using theangular-mocks
module. All failed assertions and/or uncaught errors from within aninject
-ed function are displayed asJSFiddle: http://jsfiddle.net/tybx9zwp/
Reason
The
angular.mock.inject
function catches errors, wraps them in anError
-like object (which does not inherit fromError
), transforms thestack
property, and re-throws the wrapper object. See https://github.com/angular/angular.js/blob/master/src/ngMock/angular-mocks.js#L2416. The commit which introduced this mechanism is angular/angular.js@7e91645. The given justification iswhich seems reasonable.
Solution
This can of course be fixed quickly by replacing the
instanceof
check inRunner#fail
with something likebut it is probably also a good idea to follow Angular's example and wrap
err
in anError
-like object before modifying itsstack
on https://github.com/mochajs/mocha/blob/master/lib/runner.js#L209.I would be happy to submit a PR to address this, please let me know if the above approach is acceptable.
The text was updated successfully, but these errors were encountered: