Skip to content

Commit 519000c

Browse files
committed
remove getHostChildren
1 parent ef3f5ca commit 519000c

File tree

3 files changed

+7
-81
lines changed

3 files changed

+7
-81
lines changed

src/helpers/__tests__/component-tree.test.tsx

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ import React from 'react';
22
import { Text, TextInput, View } from 'react-native';
33

44
import { render, screen } from '../..';
5-
import {
6-
getHostChildren,
7-
getHostParent,
8-
getHostSelves,
9-
getHostSiblings,
10-
getContainerElement,
11-
} from '../component-tree';
5+
import { getHostSelves, getHostSiblings, getContainerElement } from '../component-tree';
126

137
function ZeroHostChildren() {
148
return <></>;
@@ -24,49 +18,6 @@ function MultipleHostChildren() {
2418
);
2519
}
2620

27-
describe('getHostChildren()', () => {
28-
it('returns host children for host component', () => {
29-
render(
30-
<View testID="grandparent">
31-
<View testID="parent">
32-
<View testID="subject" />
33-
<Text testID="sibling">Hello</Text>
34-
</View>
35-
</View>,
36-
);
37-
38-
const hostSubject = screen.getByTestId('subject');
39-
expect(getHostChildren(hostSubject)).toEqual([]);
40-
41-
const hostSibling = screen.getByTestId('sibling');
42-
expect(getHostChildren(hostSibling)).toEqual([]);
43-
44-
const hostParent = screen.getByTestId('parent');
45-
expect(getHostChildren(hostParent)).toEqual([hostSubject, hostSibling]);
46-
47-
const hostGrandparent = screen.getByTestId('grandparent');
48-
expect(getHostChildren(hostGrandparent)).toEqual([hostParent]);
49-
});
50-
51-
it('returns host children for composite component', () => {
52-
render(
53-
<View testID="parent">
54-
<MultipleHostChildren />
55-
<View testID="subject" />
56-
<View testID="sibling" />
57-
</View>,
58-
);
59-
60-
expect(getHostChildren(screen.getByTestId('parent'))).toEqual([
61-
screen.getByTestId('child1'),
62-
screen.getByTestId('child2'),
63-
screen.getByTestId('child3'),
64-
screen.getByTestId('subject'),
65-
screen.getByTestId('sibling'),
66-
]);
67-
});
68-
});
69-
7021
describe('getHostSelves()', () => {
7122
it('returns passed element for host components', () => {
7223
render(

src/helpers/component-tree.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,6 @@ export function isElementMounted(element: HostElement) {
1414
return getContainerElement(element) === screen.container;
1515
}
1616

17-
/**
18-
* Returns host children for given element.
19-
* @param element The element start traversing from.
20-
*/
21-
export function getHostChildren(element: HostElement | null): HostElement[] {
22-
if (element == null) {
23-
return [];
24-
}
25-
26-
const hostChildren: HostElement[] = [];
27-
28-
element.children.forEach((child) => {
29-
if (typeof child !== 'object') {
30-
return;
31-
}
32-
33-
if (isHostElement(child)) {
34-
hostChildren.push(child);
35-
} else {
36-
hostChildren.push(...getHostChildren(child));
37-
}
38-
});
39-
40-
return hostChildren;
41-
}
42-
4317
/**
4418
* Return the array of host elements that represent the passed element.
4519
*

src/matchers/to-be-empty-element.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
import type { HostElement } from 'universal-test-renderer';
21
import { matcherHint, RECEIVED_COLOR } from 'jest-matcher-utils';
32
import redent from 'redent';
3+
import type { HostElement } from 'universal-test-renderer';
44

5-
import { getHostChildren } from '../helpers/component-tree';
5+
import { isHostElement } from '../helpers/component-tree';
66
import { formatElementList } from '../helpers/format-element';
77
import { checkHostElement } from './utils';
88

99
export function toBeEmptyElement(this: jest.MatcherContext, element: HostElement) {
1010
checkHostElement(element, toBeEmptyElement, this);
1111

12-
const hostChildren = getHostChildren(element);
12+
// TODO check
13+
const children = element.children.filter((child) => isHostElement(child));
1314

1415
return {
15-
pass: hostChildren.length === 0,
16+
pass: children.length === 0,
1617
message: () => {
1718
return [
1819
matcherHint(`${this.isNot ? '.not' : ''}.toBeEmptyElement`, 'element', ''),
1920
'',
2021
'Received:',
21-
`${RECEIVED_COLOR(redent(formatElementList(hostChildren), 2))}`,
22+
`${RECEIVED_COLOR(redent(formatElementList(children), 2))}`,
2223
].join('\n');
2324
},
2425
};

0 commit comments

Comments
 (0)