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
Unittest throwsXXX matchers don't compare to value in 'actual' #6761
Comments
This comment was originally written by @butlermatt Opps forgot to mention. I'm using Ubuntu Linux 64-bit, 64-bit dart editor: |
It seems correct in this example. Is this happening in other cases too, or is it just NoSuchMethodError? Added NeedsInfo label. |
This comment was originally written by @butlermatt Yes now that you mention it, it does appear to be only for NoSuchMethodErrors. My evaluation of the issue wasn't entirely correctly. This still seems unexpected to me however, for my 'actual' I expect the code I place there to throw the error, not for the attempt to run that code (ie trying to call the 'call' method). I wouldn't expect "true" to throw NoSuchMethodError, and this test should fail: test("This should fail", () { |
Added Area-Language label. |
If I understand you correctly, what you are really saying is that if the actual is not an instance of Function, then a throwsX matcher should fail. Does that sound like a reasonable interpretation? That would be an easy change to make. |
Fixed in r18401 Added Fixed label. |
This issue was originally filed by @butlermatt
In the past when we wanted to match if a piece of code would throw a specific error, we needed to wrap it in a function and assign it. Such as:
test('NoSuchMethodError', () {
var silly = true;
var broken = () => silly.doesntExist();
expect(broken, throwsNoSuchMethodError);
});
However, recently (unfortunately I'm not sure exactly how long ago it was as I've not been able to look at this project in a little while) a change to unit test has meant that the 'actual' value is never checked and if an error/exception is thrown anywhere in a test, and we have a throws.... matcher then it will pass. No matter what. Take this code for example.
test('NoSuchMethodError', () {
var silly = true;
var broken = () => silly.doesntExist();
expect(true, throwsNoSuchMethodError);
});
To me, this looks like we're saying 'true' throws NoSuchMethodError, even though it's actually detecting the throw from the anonymous function above within the test case.
My question is, is this intended behaviour to automatically catch a throw anywhere in the test case or a bug?
The text was updated successfully, but these errors were encountered: