@@ -2,6 +2,19 @@ import 'package:flutter/material.dart';
22import 'package:flutter_test/flutter_test.dart' ;
33import 'package:mockingjay/mockingjay.dart' ;
44
5+ Future <void > expectToFail (
6+ dynamic actual,
7+ Matcher matcher, {
8+ required String withMessage,
9+ }) async {
10+ try {
11+ await expectLater (actual, matcher);
12+ fail ('TestFailure expected but not thrown' );
13+ } on TestFailure catch (error) {
14+ expect (error.message, contains (withMessage));
15+ }
16+ }
17+
518void main () {
619 group ('Matchers' , () {
720 group ('isRoute' , () {
@@ -14,66 +27,72 @@ void main() {
1427
1528 group ('without arguments' , () {
1629 test ('matches any route' , () {
17- expect (createRoute (), isRoute ());
18- expect (createRoute <String >(), isRoute ());
19- expect (createRoute ('/test' ), isRoute ());
20- expect (createRoute <String >('/test' ), isRoute ());
30+ expect (createRoute < dynamic > (), isRoute < dynamic > ());
31+ expect (createRoute <String >(), isRoute < dynamic > ());
32+ expect (createRoute < dynamic > ('/test' ), isRoute < dynamic > ());
33+ expect (createRoute <String >('/test' ), isRoute < dynamic > ());
2134 });
2235
2336 test ('does not match anything that is not a route' , () {
24- expectToFail (1 , isRoute (), withMessage: 'is not a route' );
25- expectToFail ('a' , isRoute (), withMessage: 'is not a route' );
26- expectToFail (null , isRoute (), withMessage: 'is not a route' );
37+ expectToFail (1 , isRoute < dynamic > (), withMessage: 'is not a route' );
38+ expectToFail ('a' , isRoute < dynamic > (), withMessage: 'is not a route' );
39+ expectToFail (null , isRoute < dynamic > (), withMessage: 'is not a route' );
2740 expectToFail (
2841 const SizedBox (),
29- isRoute (),
42+ isRoute < dynamic > (),
3043 withMessage: 'is not a route' ,
3144 );
3245 });
3346 });
3447
3548 group ('with name argument' , () {
3649 test ('matches any route with correct name' , () {
37- expect (createRoute ('/test' ), isRoute (named: '/test' ));
38- expect (createRoute <String >('/test' ), isRoute (named: '/test' ));
50+ expect (
51+ createRoute <dynamic >('/test' ),
52+ isRoute <dynamic >(named: '/test' ),
53+ );
54+ expect (
55+ createRoute <String >('/test' ),
56+ isRoute <dynamic >(named: '/test' ),
57+ );
3958 });
4059
4160 test ('does not match anything that is not a route with that name' , () {
4261 expectToFail (
43- createRoute (),
44- isRoute (named: '/test' ),
62+ createRoute < dynamic > (),
63+ isRoute < dynamic > (named: '/test' ),
4564 withMessage:
4665 'is a route with the wrong name (actually, no name at all)' ,
4766 );
4867 expectToFail (
4968 createRoute <String >(),
50- isRoute (named: '/test' ),
69+ isRoute < dynamic > (named: '/test' ),
5170 withMessage:
5271 'is a route with the wrong name (actually, no name at all)' ,
5372 );
5473 expectToFail (
55- createRoute ('/other_name' ),
56- isRoute (named: '/test' ),
74+ createRoute < dynamic > ('/other_name' ),
75+ isRoute < dynamic > (named: '/test' ),
5776 withMessage: 'is a route with the wrong name ("/other_name")' ,
5877 );
5978 expectToFail (
6079 1 ,
61- isRoute (named: '/test' ),
80+ isRoute < dynamic > (named: '/test' ),
6281 withMessage: 'is not a route' ,
6382 );
6483 expectToFail (
6584 'a' ,
66- isRoute (named: '/test' ),
85+ isRoute < dynamic > (named: '/test' ),
6786 withMessage: 'is not a route' ,
6887 );
6988 expectToFail (
7089 null ,
71- isRoute (named: '/test' ),
90+ isRoute < dynamic > (named: '/test' ),
7291 withMessage: 'is not a route' ,
7392 );
7493 expectToFail (
7594 const SizedBox (),
76- isRoute (named: '/test' ),
95+ isRoute < dynamic > (named: '/test' ),
7796 withMessage: 'is not a route' ,
7897 );
7998 });
@@ -87,13 +106,13 @@ void main() {
87106
88107 test ('does not match anything that is not a route of that type' , () {
89108 expectToFail (
90- createRoute (),
109+ createRoute < dynamic > (),
91110 isRoute <String >(),
92111 withMessage:
93112 'is a route of the wrong type (MaterialPageRoute<dynamic>)' ,
94113 );
95114 expectToFail (
96- createRoute ('/test' ),
115+ createRoute < dynamic > ('/test' ),
97116 isRoute <String >(),
98117 withMessage:
99118 'is a route of the wrong type (MaterialPageRoute<dynamic>)' ,
@@ -116,14 +135,14 @@ void main() {
116135
117136 test ('does not match anything that is not a route of that type' , () {
118137 expectToFail (
119- createRoute (),
138+ createRoute < dynamic > (),
120139 isRoute <String >(named: '/test' ),
121140 withMessage:
122141 'is a route of the wrong type (MaterialPageRoute<dynamic>) '
123142 'and name (actually, no name at all)' ,
124143 );
125144 expectToFail (
126- createRoute ('/test' ),
145+ createRoute < dynamic > ('/test' ),
127146 isRoute <String >(named: '/test' ),
128147 withMessage:
129148 'is a route of the wrong type (MaterialPageRoute<dynamic>)' ,
@@ -159,16 +178,3 @@ void main() {
159178 });
160179 });
161180}
162-
163- Future <void > expectToFail (
164- dynamic actual,
165- Matcher matcher, {
166- required String withMessage,
167- }) async {
168- try {
169- await expectLater (actual, matcher);
170- fail ('TestFailure expected but not thrown' );
171- } on TestFailure catch (error) {
172- expect (error.message, contains (withMessage));
173- }
174- }
0 commit comments