checks 0.4.0
checks: ^0.4.0 copied to clipboard
A framework for checking values against expectations and building custom expectations.
0.4.0 #
- Breaking Changes
- Replace the
typedef ConditionandAsyncConditionfunction type callback arguments with aConditionclass which hascheck,softCheck, anddescribemethods. Use the staticitmethod in place of function literals:(it) => it.someCheck()becomes.it()..someCheck(). Most uses should have the required context type to allow the use of dot shorthands. Within collection literals where there is no context type useCondition.it<SomeType>()..someCheck(). - Remove the
describe,describeAsync,softCheck, andsoftCheckAsynctop level methods in favor of the instance members onCondition. - Swap the positional arguments to
hasso the name comes first:has((v) => v.property, 'property')becomeshas('property', (v) => v.property). A data driven fix is included, sodart fix --applywill update most call sites. Call sites where the extractor argument is staticallydynamicproduce no analysis error and will not be updated by the fix; these need to be found manually. - Expectation extension methods which take no arguments have been changed to
getters:
doesNotCompleteisDoneisEmptyisFalseisFiniteisInfiniteisNaNisNegativeisNotEmptyisNotFiniteisNotInfiniteisNotNaNisNotNegativeisNullisTrue
- Remove the public constructors for
CheckFailureandFailureDetail.
- Replace the
- Updated
Context.nestto accept an optional namednestedConditionargument which is executed against the nested subject. - Updated
Subject.isA,Subject.isNotNull,Subject.throws(sync), andSubject.returnsNormallyto accept an optionalConditionto apply to the extracted value. For examplecheck(foo).isA<int>(.it()..isGreaterThan(0)); - Updated
Subject.completes,Subject.throws(async),StreamChecks.emits, andStreamChecks.emitsErrorto returnFuture<Subject>in addition to accepting an optionalCondition. For example(await check(foo).completes()).equals(42); - Added
FutureSubjectExtension.whichto allow chaining expectations on aFuture<Subject>. - Added a runnable example for every expectation, linked from its documentation.
- Fix the failure message for
MapChecks.isNotEmptyto say that the mapis empty, instead of incorrectly repeatingis not empty. - Fix the failure message for
pairwiseMatchesto indent the nested detail about the element that failed, so that it is visibly part of the clause it describes. - Fix the failure message for
equalsIgnoringWhitespaceto report the value with its whitespace collapsed. The reported offset and difference always referred to the collapsed value, but the message showed the original, so the two did not line up. - Use a consistent lower case first word for the
Which:clause ofisA,IterableChecks.any,MapChecks.containsKeyThat, andMapChecks.containsValueThat. - Remove a stray trailing space from the failure message for
not. - Add
prints()check extensions onSubject<void Function()>andSubject<Future<void> Function()>to check expectations against captured printed output. - Improve collapsed failure messages when the only expectation on a nested
subject is a further nested subject. The inner description is joined to the
label for the outer subject with "that", so
.throws<StateError>().has('message', (e) => e.message).equals('foo')reads asthrows an error of type StateError that has message: 'foo'instead ofthrows has message: 'foo', and chainedhascalls read ashas value that has field: 'foo'instead ofhas value: has field: 'foo'. - Collapse nested subjects with a single expectation in the output of
Condition.describe, matching the format used for failure messages. For example.it()..length.equals(1)describes ashas length: <1>instead ofhas length that:followed byequals <1>on an indented line. - Collapse nested subjects with a single expectation at every depth of a
failure message. Previously only those directly under the subject with the
failing expectation collapsed; a passing sibling with multiple expectations
showed its own nested subjects in full, such as
has length that:followed byequals <3>instead ofhas length: <3>. - Collapse the failure messages for
IterableChecks.any,IterableChecks.every,MapChecks.containsKeyThat, andMapChecks.containsValueThatto a single line when the condition describes in a single line and the result fits within 80 columns, for exampleExpected: an iterable containing a value that is greater than <7>. - Describe
IterableChecks.any,IterableChecks.every,MapChecks.containsKeyThat, andMapChecks.containsValueThatin a single line when the condition describes in a single line and the result fits within 80 columns, such ascontains a value that is greater than <7>. This applies where they are one of several expectations, or are nested inside the condition of another of these expectations. - Describe the condition for
IterableChecks.everyasonly has elements where eachinstead ofonly has values that, for exampleonly has elements where each is less than <10>, so that it reads as a sentence when nested in another condition. - Fix the failure details from
Condition.softCheckwhen a precondition such asisA<T>()is rejected and further expectations follow it. The last expectation was treated as the one that failed, which triggered an assertion error, or attributed the rejection to the wrong expectation. This could be seen in the failure message forIterableChecks.every. - Omit the expectations after the one that failed from failure messages.
Within a soft check, such as the condition for
IterableChecks.every, and after an unawaited expectation which fails later, the later expectations were described as if the value satisfied them. This includes expectations made while an asynchronous expectation such ascompleteswas waiting for its value. An asynchronous expectation which has not finished when a later expectation fails is also left out, instead of being described as satisfied. - Fix the failure messages for
IterableChecks.everyand forConditionelements inIterableChecks.deepEqualsto keep the nested property for the element that failed, for exampleActual: has field: 'foo'instead ofActual: 'foo'.deepEqualsnow uses the same format asevery, withWhich:in place ofwhich. - Add
CheckFailure.describeNestedto describe a failure from soft checking a condition within thewhichof anotherRejection, in the same format as a failure message fromcheck. - Use the format of a failure message from
checkfor the conditions that failed inStreamChecks.inOrder,StreamChecks.anyOf, andIterableChecks.pairwiseMatches. Each failure now has anActual:line, whichinOrderandanyOfpreviously omitted when the condition failed without collapsing to a single line, andinOrderandanyOfno longer repeat theExpected:description of the condition. - Describe what the stream did in the
Actual:line of failures fromStreamChecks.emits,emitsError,emitsThrough,neverEmits, andisDone, instead ofa stream. For exampleemitsThroughreportsActual: a stream that closed after emitting ['a', 'b', 'c']andneverEmitsreports the values up to and including the matching one. Up to the first 25 values are listed, along with the total count for a longer stream. - Fix the failure message for
StreamChecks.emitsErrorwhen the stream emits a value, which saidclosed without emitting an error. - Require
package:meta^1.17.0. - Use the
Iterable.lastmember of the iterable forIterableChecks.lastinstead of iterating to the final element.
0.3.2 #
- Bump
testdev dependency constraint. - Add
isNotA<R>()check extension as a convenience in place ofnot((it) => it.isA<R>()). - Require Dart 3.11
- Improve speed of pretty printing for large collections.
- Improve formatting for failures involving unexpected exceptions.
- Improve formatting for failed String equality checks - indent string diff lines.
- Fix a bug when using asynchronous conditions with
mayEmitormayEmitMultiple. Note that extensions usingnestAsyncshould synchronously forward exceptions from that call. - Fix a bug when printing a failure message involving a value that returns an
empty output from
toString(). - Annotated async expectations with
@awaitNotRequiredsince tests are safely held open until expectations complete so it's not always necessary to explicitly await them. - Output more compact failure messages for simple expectations.
0.3.1 #
- Directly compare keys across actual and expected
Mapinstances when checking deep collection equality and all the keys can be directly compared for equality. This maintains the path into a nested collection for typical cases of checking for equality against a purely value collection. - Always wrap Condition descriptions in angle brackets.
- Add
containsMatchingInOrderandcontainsEqualInOrderto replace the combined functionality incontainsInOrder. - Replace
pairwiseComparesTowithpairwiseMatches. - Fix a bug where printing the result of a failed deep quality check would
fail with a
TypeErrorwhen comparing largeMapinstances. - Increase SDK constraint to ^3.5.0.
- Clarify this package is experimental.
0.3.0 #
- Breaking Changes
- Remove the
Conditionclass and theit()utility. Replace calls to(it()..someExpectation())with((it) => it.someExpectation()).
- Remove the
- Add class modifiers to restrict extension of implementation classes.
0.2.2 #
- Return the first failure from
softCheckandsoftCheckAsyncas documented, instead of the last failure when there are multiple failures. - Add example
becauseusage and mention the "reason" name in the migration guide. - Add
ComparableCheckswith comparison expectations for subject types that implementComparable.
0.2.1 #
- Add a link to file issues with feedback in the README.
0.2.0 #
- Breaking Changes
checkThatrenamed tocheck.nestandnestAsynctakeIterable<String> Function()arguments forlabelinstead ofString.- Async expectation extensions
completes,throws,emits, andemitsErrorno longer return aFuture<Subject>. Instead they take an optionalConditionargument which can check expectations that would have been checked on the returned subject. nestAsyncno longer returns aSubject, callers must pass the followupConditionto the nullable argument.- Remove the
whichextension onFuture<Subject>. matchesrenamed tomatchesPatternand now accepts aPatternargument, instead of limiting toRegExp.
- Added an example.
- Include a stack trace in the failure description for unexpected errors from Futures or Streams.
0.1.0 #
- Initial release.