|
1 | | -import type { HostElement, HostNode } from 'test-renderer'; |
| 1 | +import type { TestInstance, TestNode } from 'test-renderer'; |
2 | 2 |
|
3 | 3 | import { screen } from '../screen'; |
4 | 4 |
|
5 | 5 | /** |
6 | 6 | * Checks if the given element is a host element. |
7 | | - * @param element The element to check. |
| 7 | + * @param node The element to check. |
8 | 8 | */ |
9 | | -export function isHostElement(element?: HostNode | null): element is HostElement { |
10 | | - return typeof element !== 'string' && typeof element?.type === 'string'; |
| 9 | +export function isTestInstance(node?: TestNode | null): node is TestInstance { |
| 10 | + return typeof node !== 'string' && typeof node?.type === 'string'; |
11 | 11 | } |
12 | 12 |
|
13 | | -export function isElementMounted(element: HostElement) { |
| 13 | +export function isElementMounted(element: TestInstance) { |
14 | 14 | return getContainerElement(element) === screen.container; |
15 | 15 | } |
16 | 16 |
|
17 | 17 | /** |
18 | 18 | * Returns host siblings for given element. |
19 | | - * @param element The element start traversing from. |
| 19 | + * @param instance The element start traversing from. |
20 | 20 | */ |
21 | | -export function getHostSiblings(element: HostElement): HostElement[] { |
| 21 | +export function getInstanceSiblings(instance: TestInstance): TestInstance[] { |
22 | 22 | // Should not happen |
23 | | - const parent = element.parent; |
| 23 | + const parent = instance.parent; |
24 | 24 | if (!parent) { |
25 | 25 | return []; |
26 | 26 | } |
27 | 27 |
|
28 | 28 | return parent.children.filter( |
29 | | - (sibling) => typeof sibling !== 'string' && sibling !== element, |
30 | | - ) as HostElement[]; |
| 29 | + (sibling) => typeof sibling !== 'string' && sibling !== instance, |
| 30 | + ) as TestInstance[]; |
31 | 31 | } |
32 | 32 |
|
33 | 33 | /** |
34 | | - * Returns the containerelement of the tree. |
| 34 | + * Returns the container element of the tree. |
35 | 35 | * |
36 | | - * @param element The element start traversing from. |
| 36 | + * @param instance The element start traversing from. |
37 | 37 | * @returns The container element of the tree. |
38 | 38 | */ |
39 | | -export function getContainerElement(element: HostElement) { |
40 | | - let current = element; |
| 39 | +export function getContainerElement(instance: TestInstance) { |
| 40 | + let current = instance; |
41 | 41 | while (current.parent) { |
42 | 42 | current = current.parent; |
43 | 43 | } |
|
0 commit comments