-
Notifications
You must be signed in to change notification settings - Fork 83
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
complete coverage of javascript coalesce #86
Comments
You won't get 100% branch coverage unless it evaluates to both true and false. |
Is this an issue you deal with often? or do you write your code without coalescing for better code coverage? |
I'm open to suggestions for detecting and avoiding this. A couple of options are:
|
I could add an switch which could make the branch coverage check if the compare types are boolean at run-time. A bit more difficult, but the parser could try to determine if the result of the evaluation is an assignment, and only generate the above logic in that scenario...is that what you're after? |
I think that would be perfect. I've been thinking about how you would write that, how to know whether the right side is a bool or not. This line would be a problem in my mind: var oldFunc = null; Knowing the types of those vars when on the third line seems difficult to me, but your parser may be smarter than I think. |
This kind of shortcut is widely used in JS. I think you can safely ignore the outcome in coverage, as long as it's an assignment. BTW, the boolean checking may not be proper since boolean, albeit true or false, are sometimes desired. Afterall, it's null coalescing. |
Second though, it may be much easier to implement a option or switch to completely turn off the true false check |
OK, I've put in a CLI option, You can try the latest build at https://drone.io/github.com/tntim96/JSCover/files. Let me know if you find any issues, otherwise I'll release in a week or so. |
It works. Thanks a lot. btw, |
Great. Yes the naming is difficult, but it was the best I could think of that wasn't too long (e.g. |
is it possible to get complete coverage of this line?
this.imageFactory = stuff.imageFactory || function() { return new Image() };
it's a hack of dependency injection. it's never evaluated to false, but the right-most is always true.
The text was updated successfully, but these errors were encountered: