11import 'package:flutter/material.dart' ;
22import 'package:flutter_test/flutter_test.dart' ;
3- import 'package:matcher/src/feature_matcher.dart' ;
43import 'package:mockingjay/mockingjay.dart' ;
54
65class NonModalRoute extends Mock implements TransitionRoute <void > {}
@@ -38,46 +37,25 @@ void main() {
3837 bool fullscreenDialog = false ,
3938 }) {
4039 return MaterialPageRoute <T >(
41- settings: RouteSettings (
42- name: name,
43- arguments: arguments,
44- ),
40+ settings: RouteSettings (name: name, arguments: arguments),
4541 maintainState: maintainState,
4642 fullscreenDialog: fullscreenDialog,
4743 builder: (_) => const SizedBox (),
4844 );
4945 }
5046
5147 group ('constructor' , () {
52- test ('wraps deprecated name value in equals matcher' , () {
48+ test ('throws AssertionError when both whereSettings '
49+ 'and whereName or whereArguments matchers are provided' , () {
5350 expect (
54- // Deprecation will be removed with https://github.com/VeryGoodOpenSource/mockingjay/pull/86
55- // ignore: deprecated_member_use_from_same_package
56- isRoute (named: '/test' ),
57- isA <dynamic >().having (
58- // Deprecation will be removed with https://github.com/VeryGoodOpenSource/mockingjay/pull/86
59- // ignore: avoid_dynamic_calls
60- (dynamic m) => m.whereName,
61- 'whereName' ,
62- isA <FeatureMatcher <String >>(),
51+ () => isRoute (
52+ whereSettings: isNotNull,
53+ whereName: isNotNull,
54+ whereArguments: isNotNull,
6355 ),
56+ throwsAssertionError,
6457 );
6558 });
66-
67- test (
68- 'throws AssertionError when both whereSettings '
69- 'and whereName or whereArguments matchers are provided' ,
70- () {
71- expect (
72- () => isRoute (
73- whereSettings: isNotNull,
74- whereName: isNotNull,
75- whereArguments: isNotNull,
76- ),
77- throwsAssertionError,
78- );
79- },
80- );
8159 });
8260
8361 group ('without arguments' , () {
@@ -146,43 +124,43 @@ void main() {
146124 expect (
147125 createRoute <dynamic >(name: '/test' ),
148126 isRoute (
149- whereSettings:
150- isA <RouteSettings >().having ((s) => s.name, 'name' , '/test' ),
127+ whereSettings: isA <RouteSettings >().having (
128+ (s) => s.name,
129+ 'name' ,
130+ '/test' ,
131+ ),
151132 ),
152133 );
153134 });
154135
155- test (
156- 'does not match anything that is not a route '
157- 'with matching settings' ,
158- () {
159- expectToFail (
160- createRoute <dynamic >(name: '/test' ),
161- isRoute (whereSettings: equalsSettingsOf (createRoute <String >())),
162- withMessage:
163- "is a route where `settings` has `name` with value '/test'" ,
164- );
165- expectToFail (
166- createRoute <dynamic >(name: '/other_name' ),
167- isRoute (
168- whereSettings: equalsSettingsOf (
169- createRoute <dynamic >(name: '/test' ),
170- ),
136+ test ('does not match anything that is not a route '
137+ 'with matching settings' , () {
138+ expectToFail (
139+ createRoute <dynamic >(name: '/test' ),
140+ isRoute (whereSettings: equalsSettingsOf (createRoute <String >())),
141+ withMessage:
142+ "is a route where `settings` has `name` with value '/test'" ,
143+ );
144+ expectToFail (
145+ createRoute <dynamic >(name: '/other_name' ),
146+ isRoute (
147+ whereSettings: equalsSettingsOf (
148+ createRoute <dynamic >(name: '/test' ),
171149 ),
172- withMessage: '''
150+ ),
151+ withMessage: '''
173152is a route where `settings` has `name` with value '/other_name' which is different.
174153 Expected: /test
175154 Actual: /other_name ...
176155 ^
177156 Differ at offset 1''' ,
178- );
179- expectToFail (
180- 1 ,
181- isRoute (whereSettings: equalsSettingsOf (createRoute <dynamic >())),
182- withMessage: 'is not a route but an instance of `int`' ,
183- );
184- },
185- );
157+ );
158+ expectToFail (
159+ 1 ,
160+ isRoute (whereSettings: equalsSettingsOf (createRoute <dynamic >())),
161+ withMessage: 'is not a route but an instance of `int`' ,
162+ );
163+ });
186164 });
187165
188166 group ('with whereName argument' , () {
@@ -240,13 +218,15 @@ is a route where the route's `name` is different.
240218 expectToFail (
241219 createRoute <dynamic >(arguments: {'a' : 1 }),
242220 isRoute (whereArguments: equals ({'a' : 2 })),
243- withMessage: "is a route where the route's `arguments` "
221+ withMessage:
222+ "is a route where the route's `arguments` "
244223 "at location ['a'] is <1> instead of <2>" ,
245224 );
246225 expectToFail (
247226 createRoute <dynamic >(arguments: {'a' : 1 }),
248227 isRoute (whereArguments: equals ({'b' : 1 })),
249- withMessage: "is a route where the route's `arguments` "
228+ withMessage:
229+ "is a route where the route's `arguments` "
250230 "is missing map key 'b'" ,
251231 );
252232 expectToFail (
@@ -260,36 +240,32 @@ is a route where the route's `name` is different.
260240
261241 group ('with whereMaintainState argument' , () {
262242 test ('matches any route with matching maintainState argument' , () {
263- expect (
243+ expect (createRoute <dynamic >(), isRoute (whereMaintainState: isTrue));
244+ });
245+
246+ test ('does not match anything that is not a route with matching '
247+ 'maintainState argument' , () {
248+ expectToFail (
264249 createRoute <dynamic >(),
250+ isRoute (whereMaintainState: isFalse),
251+ withMessage:
252+ 'is a route where `maintainState` '
253+ 'is true instead of false' ,
254+ );
255+ expectToFail (
256+ NonModalRoute (),
257+ isRoute (whereMaintainState: isTrue),
258+ withMessage:
259+ 'is a route where `maintainState` '
260+ 'is not a property on `NonModalRoute` and can only be used '
261+ 'with `ModalRoute`s' ,
262+ );
263+ expectToFail (
264+ 1 ,
265265 isRoute (whereMaintainState: isTrue),
266+ withMessage: 'is not a route but an instance of `int`' ,
266267 );
267268 });
268-
269- test (
270- 'does not match anything that is not a route with matching '
271- 'maintainState argument' ,
272- () {
273- expectToFail (
274- createRoute <dynamic >(),
275- isRoute (whereMaintainState: isFalse),
276- withMessage: 'is a route where `maintainState` '
277- 'is true instead of false' ,
278- );
279- expectToFail (
280- NonModalRoute (),
281- isRoute (whereMaintainState: isTrue),
282- withMessage: 'is a route where `maintainState` '
283- 'is not a property on `NonModalRoute` and can only be used '
284- 'with `ModalRoute`s' ,
285- );
286- expectToFail (
287- 1 ,
288- isRoute (whereMaintainState: isTrue),
289- withMessage: 'is not a route but an instance of `int`' ,
290- );
291- },
292- );
293269 });
294270
295271 group ('with whereFullscreenDialog argument' , () {
@@ -300,30 +276,29 @@ is a route where the route's `name` is different.
300276 );
301277 });
302278
303- test (
304- 'does not match anything that is not a route with matching '
305- 'fullscreenDialog argument' ,
306- () {
307- expectToFail (
308- createRoute <dynamic >(fullscreenDialog: true ),
309- isRoute (whereFullscreenDialog: isFalse),
310- withMessage: 'is a route where `fullscreenDialog` '
311- 'is true instead of false' ,
312- );
313- expectToFail (
314- NonModalRoute (),
315- isRoute (whereFullscreenDialog: isFalse),
316- withMessage: 'is a route where `fullscreenDialog` '
317- 'is not a property on `NonModalRoute` and can only be used '
318- 'with `PageRoute`s' ,
319- );
320- expectToFail (
321- 1 ,
322- isRoute (whereFullscreenDialog: isTrue),
323- withMessage: 'is not a route but an instance of `int`' ,
324- );
325- },
326- );
279+ test ('does not match anything that is not a route with matching '
280+ 'fullscreenDialog argument' , () {
281+ expectToFail (
282+ createRoute <dynamic >(fullscreenDialog: true ),
283+ isRoute (whereFullscreenDialog: isFalse),
284+ withMessage:
285+ 'is a route where `fullscreenDialog` '
286+ 'is true instead of false' ,
287+ );
288+ expectToFail (
289+ NonModalRoute (),
290+ isRoute (whereFullscreenDialog: isFalse),
291+ withMessage:
292+ 'is a route where `fullscreenDialog` '
293+ 'is not a property on `NonModalRoute` and can only be used '
294+ 'with `PageRoute`s' ,
295+ );
296+ expectToFail (
297+ 1 ,
298+ isRoute (whereFullscreenDialog: isTrue),
299+ withMessage: 'is not a route but an instance of `int`' ,
300+ );
301+ });
327302 });
328303
329304 test ('returns all relevant mismatches in one log' , () {
0 commit comments