1
1
# Checking expectations with ` checks `
2
2
3
- Expectations start with ` checkThat ` . This utility returns a ` Subject ` , and
3
+ Expectations start with ` check ` . This utility returns a ` Subject ` , and
4
4
expectations can be checked against the subject. Expectations are defined as
5
5
extension methods, and different expectations will be available for subjects
6
6
with different value types.
7
7
8
8
``` dart
9
- checkThat (someValue).equals(expectedValue);
10
- checkThat (someList).deepEquals(expectedList);
11
- checkThat (someString).contains('expected pattern');
9
+ check (someValue).equals(expectedValue);
10
+ check (someList).deepEquals(expectedList);
11
+ check (someString).contains('expected pattern');
12
12
```
13
13
14
14
Multiple expectations can be checked against the same value using cascade
15
15
syntax. When multiple expectations are checked against a single value, a failure
16
16
will included descriptions of the expectations that already passed.
17
17
18
18
``` dart
19
- checkThat (someString)
19
+ check (someString)
20
20
..startsWith('a')
21
21
..endsWith('z')
22
22
..contains('lmno');
@@ -26,15 +26,15 @@ Some expectations return a `Subject` for another value derived from the original
26
26
value - for instance reading a field or awaiting the result of a Future.
27
27
28
28
``` dart
29
- checkThat (someString).length.equals(expectedLength);
30
- (await checkThat (someFuture).completes()).equals(expectedCompletion);
29
+ check (someString).length.equals(expectedLength);
30
+ (await check (someFuture).completes()).equals(expectedCompletion);
31
31
```
32
32
33
33
Fields can be extracted from objects for checking further properties with the
34
34
` has ` utility.
35
35
36
36
``` dart
37
- checkThat (someValue)
37
+ check (someValue)
38
38
.has((value) => value.property, 'property')
39
39
.equals(expectedPropertyValue);
40
40
```
@@ -47,22 +47,22 @@ value as a subject will be recorded and replayed when it is applied as a
47
47
condition. The ` it() ` utility returns a ` ConditionSubject ` .
48
48
49
49
``` dart
50
- checkThat (someList).any(it()..isGreaterThan(0));
50
+ check (someList).any(it()..isGreaterThan(0));
51
51
```
52
52
53
53
Some complicated checks may be difficult to write with parenthesized awaited
54
54
expressions, or impossible to write with cascade syntax. There are ` which `
55
55
utilities for both use cases which take a ` Condition ` .
56
56
57
57
``` dart
58
- checkThat (someString)
58
+ check (someString)
59
59
..startsWith('a')
60
60
// A cascade would not be possible on `length`
61
61
..length.which(it()
62
62
..isGreatherThan(10)
63
63
..isLessThan(100));
64
64
65
- await checkThat (someFuture)
65
+ await check (someFuture)
66
66
.completes()
67
67
.which(it()..equals(expectedCompletion));
68
68
```
@@ -126,7 +126,7 @@ extension CustomChecks on Subject<CustomType> {
126
126
127
127
# Migrating from Matchers
128
128
129
- Replace calls to ` expect ` with a call to ` checkThat ` passing the first argument.
129
+ Replace calls to ` expect ` with a call to ` check ` passing the first argument.
130
130
When a direct replacement is available, change the second argument from calling
131
131
a function returning a Matcher, to calling the extension method on the
132
132
` Subject ` .
@@ -137,9 +137,9 @@ correct replacement in `package:checks`.
137
137
138
138
``` dart
139
139
expect(actual, expected);
140
- checkThat (actual).equals(expected);
140
+ check (actual).equals(expected);
141
141
// or maybe
142
- checkThat (actual).deepEquals(expected);
142
+ check (actual).deepEquals(expected);
143
143
```
144
144
145
145
## Differences in behavior from matcher
0 commit comments