@@ -18,15 +18,15 @@ const queryByA11yRole = queryByProp.bind(null, 'accessibilityRole');
1818const queryAllByA11yRole = queryAllByProp . bind ( null , 'accessibilityRole' ) ;
1919
2020function queryAllByText (
21- { container } ,
21+ { rootInstance } ,
2222 text ,
2323 { types = [ Text , TextInput ] , exact = true , collapseWhitespace, trim, normalizer } = { } ,
2424) {
2525 const matcher = exact ? matches : fuzzyMatches ;
2626 const matchNormalizer = makeNormalizer ( { collapseWhitespace, trim, normalizer } ) ;
2727
2828 const baseArray = types . reduce (
29- ( accumulator , currentValue ) => [ ...accumulator , ...container . findAllByType ( currentValue ) ] ,
29+ ( accumulator , currentValue ) => [ ...accumulator , ...rootInstance . findAllByType ( currentValue ) ] ,
3030 [ ] ,
3131 ) ;
3232
@@ -42,10 +42,10 @@ function queryByText(...args) {
4242// 1. The error messages are specific to each one and depend on arguments
4343// 2. The stack trace will look better because it'll have a helpful method name.
4444
45- function getAllByTestId ( { container , testInstance } , id , ...rest ) {
46- const els = queryAllByTestId ( { container , testInstance } , id , ...rest ) ;
45+ function getAllByTestId ( { rootInstance , container } , id , ...rest ) {
46+ const els = queryAllByTestId ( { rootInstance , container } , id , ...rest ) ;
4747 if ( ! els . length ) {
48- throw getElementError ( `Unable to find an element with the testID: ${ id } ` , testInstance ) ;
48+ throw getElementError ( `Unable to find an element with the testID: ${ id } ` , container ) ;
4949 }
5050 return els ;
5151}
@@ -54,13 +54,10 @@ function getByTestId(...args) {
5454 return firstResultOrNull ( getAllByTestId , ...args ) ;
5555}
5656
57- function getAllByA11yRole ( { container , testInstance } , value , ...rest ) {
58- const els = queryAllByA11yRole ( { container , testInstance } , value , ...rest ) ;
57+ function getAllByA11yRole ( { rootInstance , container } , value , ...rest ) {
58+ const els = queryAllByA11yRole ( { rootInstance , container } , value , ...rest ) ;
5959 if ( ! els . length ) {
60- throw getElementError (
61- `Unable to find an element by accessibilityRole="${ value } ".` ,
62- testInstance ,
63- ) ;
60+ throw getElementError ( `Unable to find an element by accessibilityRole="${ value } ".` , container ) ;
6461 }
6562 return els ;
6663}
@@ -69,10 +66,10 @@ function getByA11yRole(...args) {
6966 return firstResultOrNull ( getAllByA11yRole , ...args ) ;
7067}
7168
72- function getAllByValue ( { container , testInstance } , value , ...rest ) {
73- const els = queryAllByValue ( { container , testInstance } , value , ...rest ) ;
69+ function getAllByValue ( { rootInstance , container } , value , ...rest ) {
70+ const els = queryAllByValue ( { rootInstance , container } , value , ...rest ) ;
7471 if ( ! els . length ) {
75- throw getElementError ( `Unable to find an element with the value: ${ value } .` , testInstance ) ;
72+ throw getElementError ( `Unable to find an element with the value: ${ value } .` , container ) ;
7673 }
7774 return els ;
7875}
@@ -81,13 +78,10 @@ function getByValue(...args) {
8178 return firstResultOrNull ( getAllByValue , ...args ) ;
8279}
8380
84- function getAllByA11yLabel ( { container , testInstance } , text , ...rest ) {
85- const els = queryAllByA11yLabel ( { container , testInstance } , text , ...rest ) ;
81+ function getAllByA11yLabel ( { rootInstance , container } , text , ...rest ) {
82+ const els = queryAllByA11yLabel ( { rootInstance , container } , text , ...rest ) ;
8683 if ( ! els . length ) {
87- throw getElementError (
88- `Unable to find an element by accessibilityLabel="${ text } "` ,
89- testInstance ,
90- ) ;
84+ throw getElementError ( `Unable to find an element by accessibilityLabel="${ text } "` , container ) ;
9185 }
9286 return els ;
9387}
@@ -96,12 +90,12 @@ function getByA11yLabel(...args) {
9690 return firstResultOrNull ( getAllByA11yLabel , ...args ) ;
9791}
9892
99- function getAllByPlaceholder ( { container , testInstance } , text , ...rest ) {
100- const els = queryAllByPlaceholder ( { container , testInstance } , text , ...rest ) ;
93+ function getAllByPlaceholder ( { rootInstance , container } , text , ...rest ) {
94+ const els = queryAllByPlaceholder ( { rootInstance , container } , text , ...rest ) ;
10195 if ( ! els . length ) {
10296 throw getElementError (
10397 `Unable to find an element with the placeholder text of: ${ text } ` ,
104- testInstance ,
98+ container ,
10599 ) ;
106100 }
107101 return els ;
@@ -111,12 +105,12 @@ function getByPlaceholder(...args) {
111105 return firstResultOrNull ( getAllByPlaceholder , ...args ) ;
112106}
113107
114- function getAllByText ( { container , testInstance } , text , ...rest ) {
115- const els = queryAllByText ( { container , testInstance } , text , ...rest ) ;
108+ function getAllByText ( { rootInstance , container } , text , ...rest ) {
109+ const els = queryAllByText ( { rootInstance , container } , text , ...rest ) ;
116110 if ( ! els . length ) {
117111 throw getElementError (
118112 `Unable to find an element with the text: ${ text } . This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.` ,
119- testInstance ,
113+ container ,
120114 ) ;
121115 }
122116 return els ;
@@ -127,9 +121,9 @@ function getByText(...args) {
127121}
128122
129123function makeFinder ( getter ) {
130- return ( defaultInstance , text , options , waitForElementOptions ) =>
124+ return ( testInstance , text , options , waitForElementOptions ) =>
131125 waitForElement (
132- ( instance = defaultInstance ) => getter ( instance , text , options ) ,
126+ ( instance = testInstance ) => getter ( instance , text , options ) ,
133127 waitForElementOptions ,
134128 ) ;
135129}
0 commit comments