Skip to content

Commit 806c9f8

Browse files
committed
refactor: fix typecheck and lint
1 parent aa182d1 commit 806c9f8

File tree

9 files changed

+20
-19
lines changed

9 files changed

+20
-19
lines changed

src/__tests__/render-debug.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as React from 'react';
44
import { Pressable, Text, TextInput, View } from 'react-native';
55
import stripAnsi from 'strip-ansi';
66
import { configure, fireEvent, render, screen } from '..';
7-
import { getConfig } from '../config';
87

98
const PLACEHOLDER_FRESHNESS = 'Add custom freshness';
109
const PLACEHOLDER_CHEF = 'Who inspected freshness?';

src/config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { DebugOptions } from './helpers/debug-deep';
2-
import type { Renderer } from './render';
32

43
/**
54
* Global configuration options for React Native Testing Library.
@@ -14,9 +13,6 @@ export type Config = {
1413

1514
/** Default options for `debug` helper. */
1615
defaultDebugOptions?: Partial<DebugOptions>;
17-
18-
/** Renderer to use for rendering components. */
19-
renderer?: Renderer;
2016
};
2117

2218
export type ConfigAliasOptions = {

src/fire-event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function isEventEnabled(
6363
) {
6464
if (isHostTextInput(nearestTouchResponder)) {
6565
return (
66-
isTextInputEditable(nearestTouchResponder) ||
66+
isTextInputEditable(nearestTouchResponder!) ||
6767
textInputEventsIgnoringEditableProp.has(eventName)
6868
);
6969
}

src/helpers/format.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import prettyFormat, { NewPlugin, plugins } from 'pretty-format';
2-
import { JsonNode } from '../renderer/render-to-json';
2+
import { JsonInstance, JsonNode } from '../renderer/render-to-json';
33

44
export type MapPropsFunction = (
55
props: Record<string, unknown>,
6-
node: JsonNode,
6+
node: JsonInstance,
77
) => Record<string, unknown>;
88

99
export type FormatOptions = {

src/helpers/host-component-names.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,38 +82,38 @@ export function isHostText(element?: HostElement | null) {
8282
* Checks if the given element is a host TextInput element.
8383
* @param element The element to check.
8484
*/
85-
export function isHostTextInput(element?: HostElement | null): element is HostElement {
85+
export function isHostTextInput(element?: HostElement | null) {
8686
return element?.type === getHostComponentNames().textInput;
8787
}
8888

8989
/**
9090
* Checks if the given element is a host Image element.
9191
* @param element The element to check.
9292
*/
93-
export function isHostImage(element?: HostElement | null): element is HostElement {
93+
export function isHostImage(element?: HostElement | null) {
9494
return element?.type === getHostComponentNames().image;
9595
}
9696

9797
/**
9898
* Checks if the given element is a host Switch element.
9999
* @param element The element to check.
100100
*/
101-
export function isHostSwitch(element?: HostElement | null): element is HostElement {
101+
export function isHostSwitch(element?: HostElement | null) {
102102
return element?.type === getHostComponentNames().switch;
103103
}
104104

105105
/**
106106
* Checks if the given element is a host ScrollView element.
107107
* @param element The element to check.
108108
*/
109-
export function isHostScrollView(element?: HostElement | null): element is HostElement {
109+
export function isHostScrollView(element?: HostElement | null) {
110110
return element?.type === getHostComponentNames().scrollView;
111111
}
112112

113113
/**
114114
* Checks if the given element is a host Modal element.
115115
* @param element The element to check.
116116
*/
117-
export function isHostModal(element?: HostElement | null): element is HostElement {
117+
export function isHostModal(element?: HostElement | null) {
118118
return element?.type === getHostComponentNames().modal;
119119
}

src/helpers/matchers/match-label-text.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { matches, TextMatch, TextMatchOptions } from '../../matches';
2+
import { HostElement } from '../../renderer/host-element';
23
import { computeAriaLabel, computeAriaLabelledBy } from '../accessibility';
34
import { findAll } from '../find-all';
45
import { matchTextContent } from './match-text-content';

src/queries/unsafe-type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,6 @@ export const bindUnsafeByTypeQueries = (instance: HostElement): UnsafeByTypeQuer
6767
});
6868

6969
function findAllByType(instance: HostElement, type: React.ComponentType<any>) {
70+
// @ts-expect-error: React.ComponentType<any> is not compatible with string
7071
return findAll(instance, (element) => element.type === type);
7172
}

src/render.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Profiler } from 'react';
33
import act from './act';
44
import { addToCleanupQueue } from './cleanup';
55
import { getConfig } from './config';
6-
import { getHostChildren } from './helpers/component-tree';
76
import debugDeep, { DebugOptions } from './helpers/debug-deep';
87
import debugShallow from './helpers/debug-shallow';
98
import { configureHostComponentNamesIfNeeded } from './helpers/host-component-names';
@@ -110,7 +109,7 @@ function buildRenderResult(
110109
toJSON: renderer.toJSON,
111110
debug: debug(instance, renderer),
112111
get root(): HostElement {
113-
return getHostChildren(instance)[0];
112+
return renderer.root;
114113
},
115114
UNSAFE_root: instance,
116115
};

src/renderer/renderer.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { ReactElement } from 'react';
22
import { Container, TestReconciler } from './reconciler';
33
import { JsonNode, renderChildrenToJson, renderToJson } from './render-to-json';
4-
import { HostElement, HostNode } from './host-element';
4+
import { HostElement } from './host-element';
55

66
export type RenderResult = {
77
update: (element: ReactElement) => void;
88
unmount: () => void;
99
container: HostElement;
10-
root: HostNode;
10+
root: HostElement;
1111
toJSON: () => JsonNode | JsonNode[] | null;
1212
};
1313

@@ -105,7 +105,7 @@ export function render(element: ReactElement): RenderResult {
105105
return HostElement.fromContainer(container);
106106
},
107107

108-
get root(): HostNode {
108+
get root(): HostElement {
109109
if (containerFiber == null || container == null) {
110110
throw new Error("Can't access .root on unmounted test renderer");
111111
}
@@ -114,7 +114,12 @@ export function render(element: ReactElement): RenderResult {
114114
throw new Error("Can't access .root on unmounted test renderer");
115115
}
116116

117-
return HostElement.fromInstance(container.children[0]);
117+
const root = HostElement.fromInstance(container.children[0]);
118+
if (typeof root === 'string') {
119+
throw new Error('Cannot render string as root element');
120+
}
121+
122+
return root;
118123
},
119124
};
120125

0 commit comments

Comments
 (0)