Skip to content

Commit b0fa427

Browse files
Merge pull request #161 from Workiva/query-root-nullable
FED-2451 Make root args to query(All)ByTestId nullable
2 parents 7b1ce54 + c3f73e5 commit b0fa427

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

CHANGELOG.md

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
## 3.0.0
44
* Add support for Dart null safety ([#155](https://github.com/Workiva/over_react_test/pull/155))
5-
* **BREAKING CHANGES**
6-
* The first argument of `queryByTestId` / `queryAllByTestId` (`root`) is now non-nullable ([#157](https://github.com/Workiva/over_react_test/pull/157)).
75
* SDK / Dependency Versioning:
86
* Increase minimum Dart SDK version from `2.11.0` to `2.13.0`.
97
* Increase minimum `react` version from `6.0.1` to `7.0.0`.

lib/src/over_react_test/react_util.dart

+8-2
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ Element? getComponentRootDomByTestId(dynamic root, String value, {String key = d
422422
/// Returns the [Element] of the first descendant of [root] that has its [key] html attribute value set to a
423423
/// space-delimited string containing [value].
424424
///
425+
/// Throws if [root] or `findDomNode(root)` is `null`. [root] is kept nullable for convenience, since the input
426+
/// to this function is often a `dynamic` component instance value.
427+
///
425428
/// Setting [searchInShadowDom] to true will allow the query to search within ShadowRoots that use `mode:"open"`.
426429
/// [shadowDepth] will limit how many layers of ShadowDOM will searched. By default it will search infinitely deep, and this
427430
/// should only be needed if there are a lot of ShadowRoots within ShadowRoots.
@@ -450,7 +453,7 @@ Element? getComponentRootDomByTestId(dynamic root, String value, {String key = d
450453
/// queryByTestId(renderedInstance, 'value'); // returns the `inner` `<div>`
451454
///
452455
/// Related: [queryAllByTestId], [getComponentRootDomByTestId].
453-
Element? queryByTestId(Object root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int? shadowDepth}) {
456+
Element? queryByTestId(dynamic root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int? shadowDepth}) {
454457
ArgumentError.checkNotNull(root, 'root');
455458

456459
final node = findDomNode(root);
@@ -464,6 +467,9 @@ Element? queryByTestId(Object root, String value, {String key = defaultTestIdKey
464467

465468
/// Returns all descendant [Element]s of [root] that has their [key] html attribute value set to [value].
466469
///
470+
/// Throws if [root] or `findDomNode(root)` is `null`. [root] is kept nullable for convenience, since the input
471+
/// to this function is often a `dynamic` component instance value.
472+
///
467473
/// Setting [searchInShadowDom] to true will allow the query to search within ShadowRoots that use `mode:"open"`.
468474
/// [shadowDepth] will limit how many layers of ShadowDOM will searched. By default it will search infinitely deep, and this
469475
/// should only be needed if there are a lot of ShadowRoots within ShadowRoots.
@@ -497,7 +503,7 @@ Element? queryByTestId(Object root, String value, {String key = defaultTestIdKey
497503
/// </div>
498504
///
499505
/// queryAllByTestId(renderedInstance, 'value'); // returns both `inner` `<div>`s
500-
List<Element> queryAllByTestId(Object root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int? shadowDepth}) {
506+
List<Element> queryAllByTestId(dynamic root, String value, {String key = defaultTestIdKey, bool searchInShadowDom = false, int? shadowDepth}) {
501507
ArgumentError.checkNotNull(root, 'root');
502508

503509
final node = findDomNode(root);

test/over_react_test/react_util_test.dart

+8
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,10 @@ main() {
809809
});
810810
});
811811

812+
test('throws when root is null', () {
813+
expect(() => queryByTestId(null, 'unusedTestId'), throwsA(isA<ArgumentError>()));
814+
});
815+
812816
test('throws a helpful error when findDomNode(root) is null', () {
813817
var jacket = mount(RendersNothing()());
814818
expect(
@@ -934,6 +938,10 @@ main() {
934938
});
935939
});
936940

941+
test('throws when root is null', () {
942+
expect(() => queryAllByTestId(null, 'unusedTestId'), throwsA(isA<ArgumentError>()));
943+
});
944+
937945
test('throws a helpful error when findDomNode(root) is null', () {
938946
var jacket = mount(RendersNothing()());
939947
expect(

0 commit comments

Comments
 (0)