Skip to content

Commit 757c975

Browse files
Merge pull request #97 from Workiva/release_over_react_test_2.9.1
RM-72266 Release over_react_test 2.9.1 (HOTFIX)
2 parents 31cbec0 + 946ede8 commit 757c975

File tree

3 files changed

+47
-38
lines changed

3 files changed

+47
-38
lines changed

lib/src/over_react_test/common_component_util.dart

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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
182160
void _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,

lib/src/over_react_test/props_meta.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414

1515
import 'package:over_react/over_react.dart';
1616
import 'package:over_react_test/jacket.dart';
17+
import 'package:react/react_client/react_interop.dart';
1718

1819
/// Returns the [UiComponent2.propsMeta] obtained by rendering [el].
1920
///
2021
/// Returns `null` if [el] does not render a UiComponent2 or does not use the
2122
/// new mixin syntax (determined by whether accessing propsMeta throws).
2223
PropsMetaCollection getPropsMeta(ReactElement el) {
24+
// ignore: invalid_use_of_protected_member
25+
final isComponent2 = ReactDartComponentVersion.fromType(el.type) == '2';
26+
if (!isComponent2) return null;
27+
2328
// Can't auto-tear down here because we're not inside a test.
2429
// Use a try-finally instead
2530
final jacket = mount(el, autoTearDown: false);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: over_react_test
2-
version: 2.9.0
2+
version: 2.9.1
33
description: A library for testing OverReact components
44
author: Workiva UI Platform Team <uip@workiva.com>
55
homepage: https://github.com/Workiva/over_react_test/

0 commit comments

Comments
 (0)