@@ -86,11 +86,10 @@ void commonComponentTests(BuilderOnlyUiFactory factory, {
86
86
bool ignoreDomProps = true ,
87
87
bool shouldTestRequiredProps = true ,
88
88
@Deprecated ('This flag is not needed as the test will auto detect the version' )
89
- bool isComponent2 = false ,
89
+ bool isComponent2,
90
90
dynamic childrenFactory ()
91
91
}) {
92
92
childrenFactory ?? = _defaultChildrenFactory;
93
- isComponent2 = ReactDartComponentVersion .fromType ((factory ()()).type) == '2' || isComponent2;
94
93
95
94
if (shouldTestPropForwarding) {
96
95
_testPropForwarding (
@@ -112,7 +111,7 @@ void commonComponentTests(BuilderOnlyUiFactory factory, {
112
111
testClassNameOverrides (factory , childrenFactory);
113
112
}
114
113
if (shouldTestRequiredProps) {
115
- testRequiredProps (factory , childrenFactory, isComponent2 );
114
+ testRequiredProps (factory , childrenFactory);
116
115
}
117
116
}
118
117
@@ -427,13 +426,23 @@ void testClassNameOverrides(BuilderOnlyUiFactory factory, dynamic childrenFactor
427
426
/// > Typically not consumed standalone. Use [commonComponentTests] instead.
428
427
///
429
428
/// __Note__: All required props must be provided by [factory] .
430
- void testRequiredProps (BuilderOnlyUiFactory factory , dynamic childrenFactory (),
431
- bool isComponent2) {
429
+ void testRequiredProps (BuilderOnlyUiFactory factory , dynamic childrenFactory ()) {
430
+ bool isComponent2;
431
+
432
432
var keyToErrorMessage = {};
433
433
var nullableProps = < String > [];
434
434
var requiredProps = < String > [];
435
435
436
436
setUp (() {
437
+ // This can't go in a setUpAll since it would be called before consumer setUps.
438
+ //
439
+ // ignore: invalid_use_of_protected_member
440
+ final version = ReactDartComponentVersion .fromType (
441
+ (factory ()(childrenFactory ())).type,
442
+ );
443
+ // ignore: invalid_use_of_protected_member
444
+ isComponent2 = version == ReactDartComponentVersion .component2;
445
+
437
446
var jacket = mount (factory ()(childrenFactory ()), autoTearDown: false );
438
447
var consumedProps = (jacket.getDartInstance () as component_base.UiComponent ).consumedProps;
439
448
jacket.unmount ();
@@ -451,37 +460,37 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory(),
451
460
}
452
461
});
453
462
454
- if (! isComponent2) {
455
- test ('throws when the required prop is not set or is null' , () {
456
- for (var propKey in requiredProps) {
457
- final reactComponentFactory = factory ()
458
- .componentFactory as ReactDartComponentFactoryProxy ; // ignore: avoid_as
459
-
460
- // Props that are defined in the default props map will never not be set.
461
- if (! reactComponentFactory.defaultProps.containsKey (propKey)) {
462
- var badRenderer = () =>
463
- render ((factory ()
464
- ..remove (propKey)
465
- )(childrenFactory ()));
466
-
467
- expect (badRenderer,
468
- throwsPropError_Required (propKey, keyToErrorMessage[propKey]),
469
- reason: '$propKey is not set' );
470
- }
463
+ test ('throws (component1) or logs the correct errors (component2) when the required prop is not set or is null' , () {
464
+ void component1RequiredPropsTest (){
465
+ for (var propKey in requiredProps) {
466
+ final reactComponentFactory = factory ()
467
+ .componentFactory as ReactDartComponentFactoryProxy ; // ignore: avoid_as
471
468
472
- var propsToAdd = {propKey: null };
469
+ // Props that are defined in the default props map will never not be set.
470
+ if (! reactComponentFactory.defaultProps.containsKey (propKey)) {
473
471
var badRenderer = () =>
474
472
render ((factory ()
475
- ..addAll (propsToAdd )
473
+ ..remove (propKey )
476
474
)(childrenFactory ()));
477
475
478
476
expect (badRenderer,
479
477
throwsPropError_Required (propKey, keyToErrorMessage[propKey]),
480
- reason: '$propKey is set to null ' );
478
+ reason: '$propKey is not set ' );
481
479
}
482
- });
483
- } else {
484
- test ('logs the correct errors when the required prop is not set or is null' , () {
480
+
481
+ var propsToAdd = {propKey: null };
482
+ var badRenderer = () =>
483
+ render ((factory ()
484
+ ..addAll (propsToAdd)
485
+ )(childrenFactory ()));
486
+
487
+ expect (badRenderer,
488
+ throwsPropError_Required (propKey, keyToErrorMessage[propKey]),
489
+ reason: '$propKey is set to null' );
490
+ }
491
+ }
492
+
493
+ void component2RequiredPropsTest () {
485
494
PropTypes .resetWarningCache ();
486
495
487
496
List <String > consoleErrors = [];
@@ -534,8 +543,10 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory(),
534
543
consoleErrors = [];
535
544
PropTypes .resetWarningCache ();
536
545
}
537
- });
538
- }
546
+ }
547
+
548
+ isComponent2 ? component2RequiredPropsTest () : component1RequiredPropsTest ();
549
+ });
539
550
540
551
test ('nullable props' , () {
541
552
if (! isComponent2) {
0 commit comments