Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

Commit 2b06196

Browse files
committed
chore: final push before release
1 parent bcde7d7 commit 2b06196

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
getQueriesForElement,
99
NativeTestEvent,
1010
prettyPrint,
11-
proxyUnsafeProperties as proxy,
11+
proxyElement as proxy,
1212
} from './lib';
1313
import act from './act-compat';
1414

src/lib/__tests__/query-helpers.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { validComponentFilter, proxyUnsafeProperties } from '../query-helpers';
1+
import { validComponentFilter, proxyElement } from '../query-helpers';
22
import { configure } from '../config';
33

44
describe('validComponentFilter > no key provided', () => {
@@ -21,9 +21,10 @@ describe('validComponentFilter > key provided', () => {
2121
});
2222
});
2323

24-
test('proxyUnsafeProperties ignores what it should', () => {
25-
const testElement = proxyUnsafeProperties({
24+
test('proxyElement ignores what it should', () => {
25+
const testElement = proxyElement({
2626
_fiber: 'should work',
27+
find: jest.fn(),
2728
findAllByProps: jest.fn(),
2829
findAllByType: jest.fn(),
2930
findByProps: jest.fn(),
@@ -32,6 +33,7 @@ test('proxyUnsafeProperties ignores what it should', () => {
3233
});
3334

3435
expect(testElement._fiber).toBe('should work');
36+
expect(testElement.find).toBe(undefined);
3537
expect(testElement.findAllByProps).toBe(undefined);
3638
expect(testElement.findAllByType).toBe(undefined);
3739
expect(testElement.findByProps).toBe(undefined);

src/lib/query-helpers.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function getChildren(node) {
3636
if (typeof child === 'string') {
3737
return child;
3838
} else if (validComponentFilter(child)) {
39-
return proxyUnsafeProperties(child);
39+
return proxyElement(child);
4040
}
4141

4242
return getChildren(child);
@@ -45,15 +45,13 @@ function getChildren(node) {
4545

4646
function getParent(node) {
4747
if (node.parent) {
48-
return validComponentFilter(node.parent)
49-
? proxyUnsafeProperties(node.parent)
50-
: getParent(node.parent);
48+
return validComponentFilter(node.parent) ? proxyElement(node.parent) : getParent(node.parent);
5149
}
5250

5351
return null;
5452
}
5553

56-
function proxyUnsafeProperties(node) {
54+
function proxyElement(node) {
5755
// We take the guiding principles seriously around these parts. These methods just let
5856
// you do too much unfortunately, and they make it hard to follow the rules of the
5957
// testing-library. It's not that we don't trust you, in fact we do trust you! We've
@@ -69,19 +67,16 @@ function proxyUnsafeProperties(node) {
6967
// need using the query methods provided on the `render` API.
7068
return new Proxy(node, {
7169
get(target, key) {
70+
const ref = target[key];
71+
7272
switch (key) {
7373
case 'findAll':
74-
const ref = target[key];
7574
return function(cb) {
76-
const overrideCb = n => cb(proxyUnsafeProperties(n));
77-
return ref
78-
.apply(this, [overrideCb])
79-
.filter(node => validComponentFilter(node))
80-
.map(proxyUnsafeProperties);
75+
const overrideCb = n => cb(proxyElement(n));
76+
return ref.apply(this, [overrideCb]);
8177
};
8278
case 'getProp':
8379
return function(prop) {
84-
/* istanbul ignore next */
8580
return target.props[prop];
8681
};
8782
case 'children':
@@ -90,6 +85,7 @@ function proxyUnsafeProperties(node) {
9085
return getParent(target);
9186
case '$$typeof':
9287
return Symbol.for('ntl.element');
88+
case 'find':
9389
case 'findAllByProps':
9490
case 'findAllByType':
9591
case 'findByProps':
@@ -98,7 +94,7 @@ function proxyUnsafeProperties(node) {
9894
return undefined;
9995
default:
10096
// Let things behave normally if you're not running a query
101-
return target[key];
97+
return ref;
10298
}
10399
},
104100
});
@@ -178,6 +174,6 @@ export {
178174
makeSingleQuery,
179175
queryAllByProp,
180176
queryByProp,
181-
proxyUnsafeProperties,
177+
proxyElement,
182178
validComponentFilter,
183179
};

typings/query-helpers.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ export const getContainer: (
3939
export const getElementError: (message: string, testRenderer: ReactTestRenderer) => Error;
4040
export const queryAllByProp: AllByProp;
4141
export const queryByProp: QueryByProp;
42-
export const proxyUnsafeProperties: (node: ReactTestInstance) => NativeTestInstance;
42+
export const proxyElement: (node: ReactTestInstance) => NativeTestInstance;

0 commit comments

Comments
 (0)