-
Notifications
You must be signed in to change notification settings - Fork 218
Should fail
and TestFailure
be exposed by scaffolding.dart?
#2073
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
Comments
I do prefer to push the
Is there behavior other than checking expectations on Do you have a concrete example that we could compare against the |
I'd like to do something like: var stopwatch = Stopwatch()..start();
try {
functionExpectedToFail();
fail('Failed to fail.');
} on ExpectedException catch (e) {
check(stopwatch.elapsed).isLessThan(timeToFailThreshold);
check(e.someProperty).deepEquals(expectedValue);
check(someTransformation(e.someOtherProperty)).deepEquals(someOtherExpectedValue);
} |
Interesting, the If we were to naively force this into full var stopwatch = Stopwatch()..start();
check(functionExpectedToFail).throws<ExpectedException>()
..has((_) => stopwatch.elapsed, 'elapsed time')
.isLessThan(timeToFailThreshold)
..has((e) => e.someProperty, 'someProperty').deepEquals(expectedValue)
..has((e) => someTransformation(e.someOtherProperty),
'some transformed property')
.deepEquals(somOtherExpectedValue); The planned codegen would only cover a small part of that check(functionExpectedToFail).throws<ExpectedException>()
..has((_) => stopwatch.elapsed, 'elapsed time')
.isLessThan(timeToFailThreshold)
- ..has((e) => e.someProperty, 'someProperty').deepEquals(expectedValue)
+ ..someProperty.deepEquals(expectedValue)
..has((e) => someTransformation(e.someOtherProperty),
'some transformed property')
.deepEquals(somOtherExpectedValue); We could write a small utility to cover the ..has((_) => stopwatch.elapsed, 'elapsed time')
.isLessThan(timeToFailThreshold)
..someProperty.deepEquals(expectedValue)
- ..has((e) => someTransformation(e.someOtherProperty),
- 'some transformed property')
- .deepEquals(somOtherExpectedValue);
+ ..someOtherProperty.transformed.deepEquals(someOtherExpectedValue);
});
}
+
+extension on Subject<PropertyType> {
+ Subject<TransformedType> get transformed => context.nest(
+ 'transformed', (value) => Extracted.value(someTransformation(value)));
+} I'm less sure what to do about the var stopwatch = Stopwatch()..start();
var exceptionSubject = check(functionExpectedToFail).throws<ExpectedException>();
check(stopwatch).elapsed.isLessThan(timeToFailThreshold);
exceptionSubject
..someProperty.deepEquals(expectedValue)
..someOtherProperty.transformed.deepEquals(someOtherExpectedValue);
// ...
extension on Subject<PropertyType> {
Subject<TransformedType> get transformed => context.nest(
'transformed', (value) => Extracted.value(someTransformation(value)));
} I can see the appeal of writing it with the I do think that cc @jakemac53 @kevmoo for any thoughts on these patterns |
I have a test that looks like:
While it's probably possible to rewrite the test to use a more typical
check(functionExpectedToFail).throws<ExpectedException>()
style, there's a significant amount of code in mycatch
block, so I think it's more readable with the explicittry
-catch
.However,
fail
(and theTestFailure
exception it wants to throw) are not exposed bypackage:test/scaffolding.dart
. Should they be? Is there something else I should use instead?(And yes, I also could just explicitly throw some other exception.)
The text was updated successfully, but these errors were encountered: