Skip to content

Commit 97bc3e9

Browse files
committed
update UTR to 0.7.0
1 parent 11ff2bb commit 97bc3e9

File tree

11 files changed

+20
-53
lines changed

11 files changed

+20
-53
lines changed

.codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ coverage:
88
target: 80% # Required patch coverage target
99
project:
1010
default:
11-
threshold: 0.5% # Allowable coverage drop in percentage points
11+
threshold: 0.5% # Allowable coverage drop in percentage points
1212

1313
comment:
1414
behavior: default

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"release-it": "^18.0.0",
9494
"typescript": "^5.6.3",
9595
"typescript-eslint": "^8.19.1",
96-
"universal-test-renderer": "0.6.0"
96+
"universal-test-renderer": "0.7.0"
9797
},
9898
"publishConfig": {
9999
"registry": "https://registry.npmjs.org"

src/__tests__/render.test.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react';
22
import { Pressable, Text, TextInput, View } from 'react-native';
3-
import { CONTAINER_TYPE } from 'universal-test-renderer';
43

54
import { fireEvent, render, type RenderAPI, screen } from '..';
65

@@ -168,14 +167,6 @@ test('returns host root', () => {
168167
expect(screen.root?.props.testID).toBe('inner');
169168
});
170169

171-
test('returns container', () => {
172-
render(<View testID="inner" />);
173-
174-
expect(screen.container).toBeDefined();
175-
expect(screen.container.type).toBe(CONTAINER_TYPE);
176-
expect(screen.container.props).toEqual({});
177-
});
178-
179170
test('RenderAPI type', () => {
180171
render(<Banana />) as RenderAPI;
181172
expect(true).toBeTruthy();

src/fire-event.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { HostElement } from 'universal-test-renderer';
99

1010
import act from './act';
1111
import { getEventHandler } from './event-handler';
12-
import { isElementMounted, isValidElement } from './helpers/component-tree';
12+
import { isElementMounted } from './helpers/component-tree';
1313
import { isHostScrollView, isHostTextInput } from './helpers/host-component-names';
1414
import { isPointerEventEnabled } from './helpers/pointer-events';
1515
import { isEditableTextInput } from './helpers/text-input';
@@ -20,10 +20,6 @@ import { EventBuilder } from './user-event/event-builder';
2020
type EventHandler = (...args: unknown[]) => unknown;
2121

2222
export function isTouchResponder(element: HostElement) {
23-
if (!isValidElement(element)) {
24-
return false;
25-
}
26-
2723
return Boolean(element.props.onStartShouldSetResponder) || isHostTextInput(element);
2824
}
2925

src/helpers/accessibility.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { AccessibilityRole, AccessibilityState, AccessibilityValue, Role }
22
import { StyleSheet } from 'react-native';
33
import type { HostElement } from 'universal-test-renderer';
44

5-
import { getContainerElement, getHostSiblings, isValidElement } from './component-tree';
5+
import { getContainerElement, getHostSiblings } from './component-tree';
66
import { findAll } from './find-all';
77
import { isHostImage, isHostSwitch, isHostText, isHostTextInput } from './host-component-names';
88
import { getTextContent } from './text-content';
@@ -158,13 +158,9 @@ export function computeAriaLabel(element: HostElement): string | undefined {
158158
const labelElementId = element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy;
159159
if (labelElementId) {
160160
const rootElement = getContainerElement(element);
161-
const labelElement = findAll(
162-
rootElement,
163-
(node) => isValidElement(node) && node.props.nativeID === labelElementId,
164-
{
165-
includeHiddenElements: true,
166-
},
167-
);
161+
const labelElement = findAll(rootElement, (node) => node.props.nativeID === labelElementId, {
162+
includeHiddenElements: true,
163+
});
168164
if (labelElement.length > 0) {
169165
return getTextContent(labelElement[0]);
170166
}

src/helpers/component-tree.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
import type { HostElement } from 'universal-test-renderer';
2-
import { CONTAINER_TYPE } from 'universal-test-renderer';
32

43
import { screen } from '../screen';
54

6-
/**
7-
* Checks if the given element is a host element.
8-
* @param element The element to check.
9-
*/
10-
export function isValidElement(element?: HostElement | null): element is HostElement {
11-
return typeof element?.type === 'string' && element.type !== CONTAINER_TYPE;
12-
}
13-
145
export function isElementMounted(element: HostElement) {
156
return getContainerElement(element) === screen.container;
167
}

src/helpers/find-all.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { HostElement } from 'universal-test-renderer';
22

33
import { getConfig } from '../config';
44
import { isHiddenFromAccessibility } from './accessibility';
5-
import { isValidElement } from './component-tree';
65

76
interface FindAllOptions {
87
/** Match elements hidden from accessibility */
@@ -55,7 +54,6 @@ function findAllInternal(
5554
if (
5655
// When matchDeepestOnly = true: add current element only if no descendants match
5756
(!options?.matchDeepestOnly || matchingDescendants.length === 0) &&
58-
isValidElement(node) &&
5957
predicate(node)
6058
) {
6159
results.push(node);
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type { HostElement } from 'universal-test-renderer';
22

3-
import { isValidElement } from './component-tree';
4-
53
export const HOST_TEXT_NAMES = ['Text', 'RCTText'];
64
const HOST_TEXT_INPUT_NAMES = ['TextInput'];
75
const HOST_IMAGE_NAMES = ['Image'];
@@ -14,45 +12,45 @@ const HOST_MODAL_NAMES = ['Modal'];
1412
* @param element The element to check.
1513
*/
1614
export function isHostText(element: HostElement | null) {
17-
return isValidElement(element) && HOST_TEXT_NAMES.includes(element.type);
15+
return element != null && HOST_TEXT_NAMES.includes(element.type);
1816
}
1917

2018
/**
2119
* Checks if the given element is a host TextInput element.
2220
* @param element The element to check.
2321
*/
2422
export function isHostTextInput(element: HostElement | null) {
25-
return isValidElement(element) && HOST_TEXT_INPUT_NAMES.includes(element.type);
23+
return element != null && HOST_TEXT_INPUT_NAMES.includes(element.type);
2624
}
2725

2826
/**
2927
* Checks if the given element is a host Image element.
3028
* @param element The element to check.
3129
*/
3230
export function isHostImage(element: HostElement | null) {
33-
return isValidElement(element) && HOST_IMAGE_NAMES.includes(element.type);
31+
return element != null && HOST_IMAGE_NAMES.includes(element.type);
3432
}
3533

3634
/**
3735
* Checks if the given element is a host Switch element.
3836
* @param element The element to check.
3937
*/
4038
export function isHostSwitch(element: HostElement | null) {
41-
return isValidElement(element) && HOST_SWITCH_NAMES.includes(element.type);
39+
return element != null && HOST_SWITCH_NAMES.includes(element.type);
4240
}
4341

4442
/**
4543
* Checks if the given element is a host ScrollView element.
4644
* @param element The element to check.
4745
*/
4846
export function isHostScrollView(element: HostElement | null) {
49-
return isValidElement(element) && HOST_SCROLL_VIEW_NAMES.includes(element.type);
47+
return element != null && HOST_SCROLL_VIEW_NAMES.includes(element.type);
5048
}
5149

5250
/**
5351
* Checks if the given element is a host Modal element.
5452
* @param element The element to check.
5553
*/
5654
export function isHostModal(element: HostElement | null) {
57-
return isValidElement(element) && HOST_MODAL_NAMES.includes(element.type);
55+
return element != null && HOST_MODAL_NAMES.includes(element.type);
5856
}

src/matchers/utils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import {
99
import redent from 'redent';
1010
import type { HostElement } from 'universal-test-renderer';
1111

12-
import { isValidElement } from '../helpers/component-tree';
13-
1412
class HostElementTypeError extends Error {
1513
constructor(received: unknown, matcherFn: jest.CustomMatcher, context: jest.MatcherContext) {
1614
super();
@@ -48,7 +46,7 @@ export function checkHostElement(
4846
matcherFn: jest.CustomMatcher,
4947
context: jest.MatcherContext,
5048
): asserts element is HostElement {
51-
if (!isValidElement(element)) {
49+
if (element == null) {
5250
throw new HostElementTypeError(element, matcherFn, context);
5351
}
5452
}

src/render.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@ function buildRenderResult(
6565
addToCleanupQueue(unmount);
6666

6767
const result = {
68-
...getQueriesForElement(renderer.container),
68+
...getQueriesForElement(renderer.root!),
6969
update,
7070
unmount,
7171
rerender: update, // alias for `update`
7272
toJSON: () => renderer.root?.toJSON(),
7373
debug: makeDebug(renderer),
74-
container: renderer.container,
7574
get root(): HostElement | null {
7675
return renderer.root;
7776
},

0 commit comments

Comments
 (0)