@@ -93,35 +93,16 @@ void commonComponentTests(BuilderOnlyUiFactory factory, {
9393 isComponent2 = ReactDartComponentVersion .fromType ((factory ()()).type) == '2' || isComponent2;
9494
9595 if (shouldTestPropForwarding) {
96- final meta = getPropsMeta (factory ()(childrenFactory ()));
97- if (meta != null ) {
98- if (getUnconsumedPropKeys != null ) {
99- unconsumedPropKeys = getUnconsumedPropKeys (meta);
100- }
101- if (getSkippedPropKeys != null ) {
102- skippedPropKeys = getSkippedPropKeys (meta);
103- }
104-
105- unconsumedPropKeys = _flatten (unconsumedPropKeys).toList ();
106- skippedPropKeys = _flatten (skippedPropKeys).toList ();
107-
108- _testPropForwarding (
109- factory ,
110- childrenFactory,
111- meta: meta,
112- unconsumedPropKeys: unconsumedPropKeys,
113- ignoreDomProps: ignoreDomProps,
114- skippedPropKeys: skippedPropKeys,
115- nonDefaultForwardingTestProps: nonDefaultForwardingTestProps,
116- );
117- } else {
118- if (getUnconsumedPropKeys != null || getSkippedPropKeys != null ) {
119- throw ArgumentError (
120- 'This component does not correspond to a mixin-based syntax component,'
121- ' and thus cannot be used with the function syntax to specify '
122- 'unconsumedPropKeys/skippedPropKeys' );
123- }
124- }
96+ _testPropForwarding (
97+ factory ,
98+ childrenFactory,
99+ unconsumedPropKeys: unconsumedPropKeys,
100+ skippedPropKeys: skippedPropKeys,
101+ getUnconsumedPropKeys: getUnconsumedPropKeys,
102+ getSkippedPropKeys: getSkippedPropKeys,
103+ ignoreDomProps: ignoreDomProps,
104+ nonDefaultForwardingTestProps: nonDefaultForwardingTestProps,
105+ );
125106 }
126107
127108 if (shouldTestClassNameMerging) {
@@ -173,20 +154,43 @@ void expectCleanTestSurfaceAtEnd() {
173154
174155/// Common test for verifying that unconsumed props are forwarded as expected.
175156///
176- /// [meta] must contain all props mixed in by the component
177- /// (e.g., [UiComponent2.propsMeta] ).
178- ///
179157/// > Typically not consumed standalone. Use [commonComponentTests] instead.
180158///
181159/// todo make this public again if there's a need to expose it, once the API has stabilized
182160void _testPropForwarding (BuilderOnlyUiFactory factory , dynamic childrenFactory (), {
183- @required component_base.PropsMetaCollection meta,
184- List unconsumedPropKeys = const [],
185- bool ignoreDomProps = true ,
186- List skippedPropKeys = const [],
187- Map nonDefaultForwardingTestProps = const {}
161+ @required List unconsumedPropKeys,
162+ @required List skippedPropKeys,
163+ @required List Function (PropsMetaCollection ) getUnconsumedPropKeys,
164+ @required List Function (PropsMetaCollection ) getSkippedPropKeys,
165+ @required ignoreDomProps,
166+ @required nonDefaultForwardingTestProps,
188167}) {
189168 test ('forwards unconsumed props as expected' , () {
169+ // This needs to be retrieved inside a `test`/`setUp`/etc, not inside a group,
170+ // in case childrenFactory relies on variables set up in the consumer's setUp blocks.
171+ final meta = getPropsMeta ((factory ())(childrenFactory ()));
172+
173+ // We can't test this component if it doesn't have meta.
174+ if (meta == null ) {
175+ if (getUnconsumedPropKeys != null || getSkippedPropKeys != null ) {
176+ throw ArgumentError (
177+ 'This component does not correspond to a mixin-based syntax component,'
178+ ' and thus cannot be used with the function syntax to specify '
179+ 'unconsumedPropKeys/skippedPropKeys' );
180+ }
181+
182+ return ;
183+ }
184+
185+ if (getUnconsumedPropKeys != null ) {
186+ unconsumedPropKeys = getUnconsumedPropKeys (meta);
187+ }
188+ if (getSkippedPropKeys != null ) {
189+ skippedPropKeys = getSkippedPropKeys (meta);
190+ }
191+ unconsumedPropKeys = _flatten (unconsumedPropKeys).toList ();
192+ skippedPropKeys = _flatten (skippedPropKeys).toList ();
193+
190194 const Map extraProps = {
191195 // Add this so we find the right component(s) with [getForwardingTargets] later.
192196 forwardedPropBeacon: true ,
0 commit comments