-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Improve matcher isInstanceOf now that Dart has first class types. #15381
Comments
Removed Type-Defect label. |
Removed Area-UnitTest label. |
Removed Pkg-Unittest label. |
This comment was originally written by @vicb This is something I have implemented in Guinness as: bool matches(obj, Map matchState) => see https://github.com/vsavkin/guinness/blob/5f9e291f9c0937a19ab278b0afe7c377bfae25fe/lib/src/common/unittest_backend.dart#L191 for the full Matcher We have started to discuss this with Kevin: https://plus.google.com/u/0/+VictorBerchet/posts/bdDgAfUB9bW?cfem=1 I'm not clear on how this would affect the generated code size:
(I've not really considered JS & its code size for my use case. The reasoning being that if the tests pass with Dart, they should pass after dart2js, if not then this is a dart2js and not your own code issue. The tests are supposed to test your own code, not dart2js - still I'm all for testing with dart2js to help stabilize the tools as long as there is no constraint on my development flow). |
This comment was originally written by greg...@gmail.com I was under the impression that this was already possible: bool isInstance(obj, Type type) => obj is type; "malformed type: line 5 pos 18: using 't' in this context is invalid" I wonder if there is a bug for implementing this - or if it is not possible. In the VM it must just be an int check. Not sure about dart2js. |
This comment was originally written by greg.lo...@gmail.com Erm - "But it looks like this is NOT possible - yet?" |
This comment was originally written by @seaneagan In issue #10406 gbracha indicates that this will only be possible via mirrors. Matchers that use mirrors are currently put here: http://www.dartdocs.org/documentation/matcher/0.11.1/index.html#matcher/matcher-mirror_matchers Also this issue is a duplicate of issue #10407 which was wrongly merged with issue #8138. |
This comment was originally written by @seaneagan Once this is fixed, all the custom |
This issue has been moved to dart-lang/test#2334. |
This issue was originally filed by greg...@gmail.com
Current: new isInstanceOf<T>(T t)
New: isInstanceOf2(Type t). // But with a better name.
Consider adding:
throwsType(Type t)
Also worth updating these docs:
"As types are not first class objects in Dart we can only approximate this test by using a generic wrapper class."
"Note that this does not currently work in dart2js; it will match any type, and isNot(new isInstanceof<T>()) will always fail. This is because dart2js currently ignores template type parameters."
https://api.dartlang.org/docs/channels/stable/latest/matcher/isInstanceOf.html
https://www.dartlang.org/articles/writing-unit-tests-for-pub-packages/
The text was updated successfully, but these errors were encountered: