@@ -348,10 +348,15 @@ Matcher throwsPropError_Combination(String propName, String prop2Name, [String m
348
348
/// logs that are emitted during the function runtime.
349
349
class _LoggingFunctionMatcher extends CustomMatcher {
350
350
_LoggingFunctionMatcher (dynamic matcher, {this .config, description, name})
351
- : super (description ?? 'emits the logs' , name ?? 'logs' , wrapMatcher (matcher));
351
+ : super (description ?? 'emits the logs' , name ?? 'logs' , _wrapMatcherForSingleLog (matcher));
352
352
353
353
final ConsoleConfiguration config;
354
354
355
+ static dynamic _wrapMatcherForSingleLog (dynamic expected) {
356
+ if (expected is Matcher || expected is List ) return expected;
357
+ return contains (expected);
358
+ }
359
+
355
360
@override
356
361
featureValueOf (actual) {
357
362
var logs = < String > [];
@@ -378,8 +383,8 @@ class _LoggingFunctionMatcher extends CustomMatcher {
378
383
/// `errorConfig` , the actual list of logs will include the error message from the
379
384
/// caught error.
380
385
///
381
- /// Related: [emitsLogs ] , [emitsNoLogs ]
382
- Matcher emitsLog ( String expected, {ConsoleConfiguration consoleConfig}) =>
386
+ /// Related: [logsToConsole ] , [hasNoLogs ]
387
+ Matcher hasLog ( dynamic expected, {ConsoleConfiguration consoleConfig}) =>
383
388
_LoggingFunctionMatcher (anyElement (contains (expected)), config: consoleConfig);
384
389
385
390
/// A Matcher used to compare a list of logs against a provided matcher.
@@ -392,10 +397,10 @@ Matcher emitsLog(String expected, {ConsoleConfiguration consoleConfig}) =>
392
397
/// __Examples:__
393
398
///
394
399
/// To look for a specific `String` in any log index, the best solution is to use
395
- /// [emitsLog ] , but the behavior can be mimicked by passing in the correct `Iterable`
400
+ /// [hasLog ] , but the behavior can be mimicked by passing in the correct `Iterable`
396
401
/// matchers.
397
402
/// ```dart
398
- /// expect(callbackFunction, emitsLogs (anyElement(contains('I expect this log'))));
403
+ /// expect(callbackFunction, logsToConsole (anyElement(contains('I expect this log'))));
399
404
/// ```
400
405
///
401
406
/// When passed a `List` , the matcher will do an equality check on the actual
@@ -404,34 +409,34 @@ Matcher emitsLog(String expected, {ConsoleConfiguration consoleConfig}) =>
404
409
/// Alternatively, the `String` can be wrapped in a `contains` to check the
405
410
/// if the comparable index contains that substring.
406
411
/// ```dart
407
- /// expect(callbackFunction, emitsLogs (['I expect this log', 'And this Log']));
408
- /// expect(callbackFunction, emitsLogs ([
412
+ /// expect(callbackFunction, logsToConsole (['I expect this log', 'And this Log']));
413
+ /// expect(callbackFunction, logsToConsole ([
409
414
/// contains('I expect'),
410
415
/// contains('And this'),
411
416
/// ]));
412
417
/// ```
413
418
///
414
419
/// All usual `Iterable` matchers can also be used.
415
420
/// ```dart
416
- /// expect(callbackFunction, emitsLogs (containsAll(['I expect this log'])));
417
- /// expect(callbackFunction, emitsLogs (containsAllInOrder(['I expect this log'])));
418
- /// expect(callbackFunction, emitsLogs (hasLength(1)));
421
+ /// expect(callbackFunction, logsToConsole (containsAll(['I expect this log'])));
422
+ /// expect(callbackFunction, logsToConsole (containsAllInOrder(['I expect this log'])));
423
+ /// expect(callbackFunction, logsToConsole (hasLength(1)));
419
424
/// ```
420
425
///
421
- /// Related: [emitsLog ] , [emitsNoLogs ]
422
- Matcher emitsLogs (dynamic expected, {ConsoleConfiguration consoleConfig}) =>
426
+ /// Related: [hasLog ] , [hasNoLogs ]
427
+ Matcher logsToConsole (dynamic expected, {ConsoleConfiguration consoleConfig}) =>
423
428
_LoggingFunctionMatcher (expected, config: consoleConfig);
424
429
425
430
/// A matcher to verify that a callback function does not emit any logs.
426
431
///
427
432
/// In the case the actual value is a callback that is run, any errors caused by
428
433
/// the callback will be caught and ignored.
429
434
///
430
- /// Related: [emitsLogs ]
431
- final Matcher emitsNoLogs = _LoggingFunctionMatcher (isEmpty);
435
+ /// Related: [logsToConsole ]
436
+ final Matcher hasNoLogs = _LoggingFunctionMatcher (isEmpty);
432
437
433
438
/// The string used to identify a `propType` error.
434
- const _propTypeErrorMessage = 'Failed prop type' ;
439
+ const _propTypeErrorPrefix = 'Failed prop type' ;
435
440
436
441
/// A matcher used to assert an actual `List` contains expected `propType`
437
442
/// warnings.
@@ -447,7 +452,7 @@ class _PropTypeLogMatcher extends _LoggingFunctionMatcher {
447
452
description: 'emits the propType warning' ,
448
453
name: 'propType warning' );
449
454
450
- final _filter = contains (_propTypeErrorMessage );
455
+ final _filter = contains (_propTypeErrorPrefix );
451
456
452
457
@override
453
458
featureValueOf (actual) {
@@ -463,7 +468,7 @@ class _PropTypeLogMatcher extends _LoggingFunctionMatcher {
463
468
/// Matcher used to check for a specific `propType` warning being emitted during
464
469
/// the runtime of a callback function.
465
470
///
466
- /// Has the same underlying logic as [emitsLog ] , with the difference being that
471
+ /// Has the same underlying logic as [hasLog ] , with the difference being that
467
472
/// console configuration is set to `errorConfig` and non-propType related warnings
468
473
/// are filtered out of the list.
469
474
///
@@ -472,14 +477,14 @@ class _PropTypeLogMatcher extends _LoggingFunctionMatcher {
472
477
/// is set to `errorConfig` , the actual list of logs will include the error
473
478
/// message from the caught error.
474
479
///
475
- /// Related: [emitsPropTypeWarnings ] , [emitsNoPropTypeWarnings ] , [emitsLog ]
476
- _PropTypeLogMatcher emitsPropTypeWarning (String expected) =>
480
+ /// Related: [logsPropTypeWarnings ] , [logsNoPropTypeWarnings ] , [hasLog ]
481
+ _PropTypeLogMatcher logsPropTypeWarning (String expected) =>
477
482
_PropTypeLogMatcher (anyElement (contains (expected)));
478
483
479
484
/// Matcher used to check for specific `propType` warnings being emitted during
480
485
/// the runtime of a callback function.
481
486
///
482
- /// Has the same underlying logic as [emitsLogs ] , with the difference being that
487
+ /// Has the same underlying logic as [logsToConsole ] , with the difference being that
483
488
/// console configuration is set to `errorConfig` and non-propType related warnings
484
489
/// are filtered out of the list.
485
490
///
@@ -488,8 +493,8 @@ _PropTypeLogMatcher emitsPropTypeWarning(String expected) =>
488
493
/// is set to `errorConfig` , the actual list of logs will include the error
489
494
/// message from the caught error.
490
495
///
491
- /// Related: [emitsPropTypeWarning ] , [emitsNoPropTypeWarnings ] , [emitsLogs ]
492
- _PropTypeLogMatcher emitsPropTypeWarnings (dynamic expected) =>
496
+ /// Related: [logsPropTypeWarnings ] , [logsNoPropTypeWarnings ] , [logsToConsole ]
497
+ _PropTypeLogMatcher logsPropTypeWarnings (dynamic expected) =>
493
498
_PropTypeLogMatcher (expected);
494
499
495
500
/// Matcher used enforce that there are no `propType` warnings.
@@ -499,5 +504,43 @@ _PropTypeLogMatcher emitsPropTypeWarnings(dynamic expected) =>
499
504
/// is set to `errorConfig` , the actual list of logs will include the error
500
505
/// message from the caught error.
501
506
///
502
- /// Related: [emitsPropTypeWarning] , [emitsPropTypeWarnings]
503
- final _PropTypeLogMatcher emitsNoPropTypeWarnings = _PropTypeLogMatcher (isEmpty);
507
+ /// Related: [logsPropTypeWarning] , [logsPropTypeWarnings]
508
+ final _PropTypeLogMatcher logsNoPropTypeWarnings = _PropTypeLogMatcher (isEmpty);
509
+
510
+ /// A matcher to verify that a [PropError] is thrown with a provided `propName` and `message` .
511
+ ///
512
+ /// This matcher is built on top of [logsPropTypeWarning] and has the same behavior
513
+ /// of running a provided callback, swallowing errors that occur, and looking
514
+ /// for the expected [PropError] in the resulting logs.
515
+ _PropTypeLogMatcher logsPropError (String propName, [String message = '' ]) {
516
+ return logsPropTypeWarning ('PropError: Prop $propName $message ' .trim ());
517
+ }
518
+
519
+ /// A matcher to verify that a [PropError] .required is thrown with a provided `propName` and `message` .
520
+ ///
521
+ /// This matcher is built on top of [logsPropTypeWarning] and has the same behavior
522
+ /// of running a provided callback, swallowing errors that occur, and looking
523
+ /// for the expected [PropError] in the resulting logs.
524
+ _PropTypeLogMatcher logsRequiredPropError (String propName, [String message = '' ]) {
525
+ return logsPropTypeWarning ('RequiredPropError: Prop $propName is required. $message ' .trim ());
526
+ }
527
+
528
+ /// A matcher to verify that a [PropError] .value is thrown with a provided `invalidValue` , `propName` , and `message` .
529
+ ///
530
+ /// This matcher is built on top of [logsPropTypeWarning] and has the same behavior
531
+ /// of running a provided callback, swallowing errors that occur, and looking
532
+ /// for the expected [PropError] in the resulting logs.
533
+ _PropTypeLogMatcher logsValuePropError (dynamic invalidValue, String propName, [String message = '' ]) {
534
+ return logsPropTypeWarning ('InvalidPropValueError: Prop $propName set to $invalidValue . '
535
+ '$message ' .trim ());
536
+ }
537
+
538
+ /// A matcher to verify that a [PropError] is thrown with a provided `propName` , `prop2Name` , and `message` .
539
+ ///
540
+ /// This matcher is built on top of [logsPropTypeWarning] and has the same behavior
541
+ /// of running a provided callback, swallowing errors that occur, and looking
542
+ /// for the expected [PropError] in the resulting logs.
543
+ _PropTypeLogMatcher logsCombinationPropError (String propName, String prop2Name, [String message = '' ]) {
544
+ return logsPropTypeWarning ('InvalidPropCombinationError: Prop $propName and prop $prop2Name are set to '
545
+ 'incompatible values. $message ' .trim ());
546
+ }
0 commit comments