Skip to main content

checks 0.4.0 copy "checks: ^0.4.0" to clipboard
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 Condition and AsyncCondition function type callback arguments with a Condition class which has check, softCheck, and describe methods. Use the static it method 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 use Condition.it<SomeType>()..someCheck().
    • Remove the describe, describeAsync, softCheck, and softCheckAsync top level methods in favor of the instance members on Condition.
    • Swap the positional arguments to has so the name comes first: has((v) => v.property, 'property') becomes has('property', (v) => v.property). A data driven fix is included, so dart fix --apply will update most call sites. Call sites where the extractor argument is statically dynamic produce 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:
      • doesNotComplete
      • isDone
      • isEmpty
      • isFalse
      • isFinite
      • isInfinite
      • isNaN
      • isNegative
      • isNotEmpty
      • isNotFinite
      • isNotInfinite
      • isNotNaN
      • isNotNegative
      • isNull
      • isTrue
    • Remove the public constructors for CheckFailure and FailureDetail.
  • Updated Context.nest to accept an optional named nestedCondition argument which is executed against the nested subject.
  • Updated Subject.isA, Subject.isNotNull, Subject.throws (sync), and Subject.returnsNormally to accept an optional Condition to apply to the extracted value. For example check(foo).isA<int>(.it()..isGreaterThan(0));
  • Updated Subject.completes, Subject.throws (async), StreamChecks.emits, and StreamChecks.emitsError to return Future<Subject> in addition to accepting an optional Condition. For example (await check(foo).completes()).equals(42);
  • Added FutureSubjectExtension.which to allow chaining expectations on a Future<Subject>.
  • Added a runnable example for every expectation, linked from its documentation.
  • Fix the failure message for MapChecks.isNotEmpty to say that the map is empty, instead of incorrectly repeating is not empty.
  • Fix the failure message for pairwiseMatches to 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 equalsIgnoringWhitespace to 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 of isA, IterableChecks.any, MapChecks.containsKeyThat, and MapChecks.containsValueThat.
  • Remove a stray trailing space from the failure message for not.
  • Add prints() check extensions on Subject<void Function()> and Subject<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 as throws an error of type StateError that has message: 'foo' instead of throws has message: 'foo', and chained has calls read as has value that has field: 'foo' instead of has 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 as has length: <1> instead of has length that: followed by equals <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 by equals <3> instead of has length: <3>.
  • Collapse the failure messages for IterableChecks.any, IterableChecks.every, MapChecks.containsKeyThat, and MapChecks.containsValueThat to a single line when the condition describes in a single line and the result fits within 80 columns, for example Expected: an iterable containing a value that is greater than <7>.
  • Describe IterableChecks.any, IterableChecks.every, MapChecks.containsKeyThat, and MapChecks.containsValueThat in a single line when the condition describes in a single line and the result fits within 80 columns, such as contains 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.every as only has elements where each instead of only has values that, for example only 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.softCheck when a precondition such as isA<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 for IterableChecks.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 as completes was 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.every and for Condition elements in IterableChecks.deepEquals to keep the nested property for the element that failed, for example Actual: has field: 'foo' instead of Actual: 'foo'. deepEquals now uses the same format as every, with Which: in place of which.
  • Add CheckFailure.describeNested to describe a failure from soft checking a condition within the which of another Rejection, in the same format as a failure message from check.
  • Use the format of a failure message from check for the conditions that failed in StreamChecks.inOrder, StreamChecks.anyOf, and IterableChecks.pairwiseMatches. Each failure now has an Actual: line, which inOrder and anyOf previously omitted when the condition failed without collapsing to a single line, and inOrder and anyOf no longer repeat the Expected: description of the condition.
  • Describe what the stream did in the Actual: line of failures from StreamChecks.emits, emitsError, emitsThrough, neverEmits, and isDone, instead of a stream. For example emitsThrough reports Actual: a stream that closed after emitting ['a', 'b', 'c'] and neverEmits reports 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.emitsError when the stream emits a value, which said closed without emitting an error.
  • Require package:meta ^1.17.0.
  • Use the Iterable.last member of the iterable for IterableChecks.last instead of iterating to the final element.

0.3.2 #

  • Bump test dev dependency constraint.
  • Add isNotA<R>() check extension as a convenience in place of not((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 mayEmit or mayEmitMultiple. Note that extensions using nestAsync should 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 @awaitNotRequired since 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 Map instances 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 containsMatchingInOrder and containsEqualInOrder to replace the combined functionality in containsInOrder.
  • Replace pairwiseComparesTo with pairwiseMatches.
  • Fix a bug where printing the result of a failed deep quality check would fail with a TypeError when comparing large Map instances.
  • Increase SDK constraint to ^3.5.0.
  • Clarify this package is experimental.

0.3.0 #

  • Breaking Changes
    • Remove the Condition class and the it() utility. Replace calls to (it()..someExpectation()) with ((it) => it.someExpectation()).
  • Add class modifiers to restrict extension of implementation classes.

0.2.2 #

  • Return the first failure from softCheck and softCheckAsync as documented, instead of the last failure when there are multiple failures.
  • Add example because usage and mention the "reason" name in the migration guide.
  • Add ComparableChecks with comparison expectations for subject types that implement Comparable.

0.2.1 #

  • Add a link to file issues with feedback in the README.

0.2.0 #

  • Breaking Changes
    • checkThat renamed to check.
    • nest and nestAsync take Iterable<String> Function() arguments for label instead of String.
    • Async expectation extensions completes, throws, emits, and emitsError no longer return a Future<Subject>. Instead they take an optional Condition argument which can check expectations that would have been checked on the returned subject.
    • nestAsync no longer returns a Subject, callers must pass the followup Condition to the nullable argument.
    • Remove the which extension on Future<Subject>.
    • matches renamed to matchesPattern and now accepts a Pattern argument, instead of limiting to RegExp.
  • Added an example.
  • Include a stack trace in the failure description for unexpected errors from Futures or Streams.

0.1.0 #

  • Initial release.
126
likes
160
points
173k
downloads

Documentation

API reference

Publisher

verified publisherlabs.dart.dev

Weekly Downloads

A framework for checking values against expectations and building custom expectations.

Repository (GitHub)
View/report issues
Contributing

License

BSD-3-Clause (license)

Dependencies

async, meta, test_api

More

Packages that depend on checks