Skip to content

Commit bcbb278

Browse files
committed
tweaks
1 parent 87ffd32 commit bcbb278

File tree

12 files changed

+46
-41
lines changed

12 files changed

+46
-41
lines changed

src/__tests__/react-native-animated.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import type { ViewStyle } from 'react-native';
3-
import { Animated } from 'react-native';
3+
import { Animated, Text } from 'react-native';
44

55
import { act, render, screen } from '..';
66

@@ -46,7 +46,7 @@ describe('AnimatedView', () => {
4646
it('should use native driver when useNativeDriver is true', async () => {
4747
await render(
4848
<AnimatedView fadeInDuration={250} useNativeDriver={true}>
49-
Test
49+
<Text>Test</Text>
5050
</AnimatedView>,
5151
);
5252
expect(screen.root).toHaveStyle({ opacity: 0 });
@@ -59,7 +59,7 @@ describe('AnimatedView', () => {
5959
it('should not use native driver when useNativeDriver is false', async () => {
6060
await render(
6161
<AnimatedView fadeInDuration={250} useNativeDriver={false}>
62-
Test
62+
<Text>Test</Text>
6363
</AnimatedView>,
6464
);
6565
expect(screen.root).toHaveStyle({ opacity: 0 });

src/__tests__/render-hook.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ test('handles hook with suspense', async () => {
203203
});
204204

205205
class ErrorBoundary extends React.Component<
206-
{ children: React.ReactNode; fallback: string },
206+
{ children: React.ReactNode; fallback: React.ReactNode },
207207
{ hasError: boolean }
208208
> {
209-
constructor(props: { children: React.ReactNode; fallback: string }) {
209+
constructor(props: { children: React.ReactNode; fallback: React.ReactNode }) {
210210
super(props);
211211
this.state = { hasError: false };
212212
}
@@ -233,7 +233,7 @@ test('handles hook suspense with error boundary', async () => {
233233
const { result } = await renderHook(useSuspendingHook, {
234234
initialProps: promise,
235235
wrapper: ({ children }) => (
236-
<ErrorBoundary fallback="error-fallback">
236+
<ErrorBoundary fallback={<Text>Error Fallback</Text>}>
237237
<React.Suspense fallback={<Text>Loading...</Text>}>{children}</React.Suspense>
238238
</ErrorBoundary>
239239
),

src/__tests__/timers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import waitFor from '../wait-for';
1+
import { waitFor } from '../wait-for';
22

33
describe.each([false, true])('fake timers tests (legacyFakeTimers = %s)', (legacyFakeTimers) => {
44
beforeEach(() => {

src/helpers/host-component-names.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { HostElement } from 'universal-test-renderer';
22

3-
const HOST_TEXT_NAMES = ['Text', 'RCTText'];
3+
export const HOST_TEXT_NAMES = ['Text', 'RCTText'];
44
const HOST_TEXT_INPUT_NAMES = ['TextInput'];
55
const HOST_IMAGE_NAMES = ['Image'];
66
const HOST_SWITCH_NAMES = ['RCTSwitch'];

src/matchers/__tests__/to-have-text-content.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { render, screen } from '../..';
66
test('toHaveTextContent() example test', async () => {
77
await render(
88
<View testID="view">
9-
<Text>Hello</Text> <Text>World</Text>
9+
<Text>Hello</Text>
10+
<Text> </Text>
11+
<Text>World</Text>
1012
</View>,
1113
);
1214

src/pure.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export { default as act } from './act';
22
export { cleanup } from './cleanup';
33
export { fireEvent, unsafe_fireEventSync } from './fire-event';
4-
export { default as render } from './render';
5-
export { default as unsafe_renderSync } from './deprecated/render-sync';
6-
export { default as waitFor } from './wait-for';
7-
export { default as waitForElementToBeRemoved } from './wait-for-element-to-be-removed';
4+
export { render } from './render';
5+
export { unsafe_renderSync } from './unsafe-render-sync';
6+
export { waitFor } from './wait-for';
7+
export { waitForElementToBeRemoved } from './wait-for-element-to-be-removed';
88
export { within, getQueriesForElement } from './within';
99

1010
export { configure, resetToDefaults } from './config';
@@ -14,7 +14,7 @@ export { renderHook, unsafe_renderHookSync } from './render-hook';
1414
export { screen } from './screen';
1515
export { userEvent } from './user-event';
1616

17-
export type { RenderSyncOptions, RenderSyncResult, DebugFunction } from './deprecated/render-sync';
17+
export type { RenderSyncOptions, RenderSyncResult, DebugFunction } from './unsafe-render-sync';
1818
export type { RenderOptions, RenderResult, RenderResult as RenderAPI } from './render';
1919
export type { RenderHookOptions, RenderHookResult, RenderHookSyncResult } from './render-hook';
2020
export type { Config } from './config';

src/queries/make-queries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { formatJson } from '../helpers/format-element';
55
import { logger } from '../helpers/logger';
66
import { screen } from '../screen';
77
import type { WaitForOptions } from '../wait-for';
8-
import waitFor from '../wait-for';
8+
import { waitFor } from '../wait-for';
99

1010
export type GetByQuery<Predicate, Options = void> = (
1111
predicate: Predicate,

src/render-hook.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from 'react';
22

3-
import unsafe_renderSync from './deprecated/render-sync';
4-
import render from './render';
3+
import { render } from './render';
54
import type { RefObject } from './types';
5+
import { unsafe_renderSync } from './unsafe-render-sync';
66

77
export type RenderHookResult<Result, Props> = {
88
result: RefObject<Result>;

src/render.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { addToCleanupQueue } from './cleanup';
66
import { getConfig } from './config';
77
import type { DebugOptions } from './helpers/debug';
88
import { debug } from './helpers/debug';
9+
import { HOST_TEXT_NAMES } from './helpers/host-component-names';
910
import { renderWithAsyncAct } from './render-act';
1011
import { setRenderResult } from './screen';
1112
import { getQueriesForElement } from './within';
@@ -18,7 +19,7 @@ export interface RenderOptions {
1819
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1920
wrapper?: React.ComponentType<any>;
2021

21-
createNodeMock?: (element: React.ReactElement) => unknown;
22+
createNodeMock?: (element: React.ReactElement) => object;
2223
}
2324

2425
export type RenderResult = Awaited<ReturnType<typeof render>>;
@@ -27,14 +28,13 @@ export type RenderResult = Awaited<ReturnType<typeof render>>;
2728
* Renders test component deeply using React Test Renderer and exposes helpers
2829
* to assert on the output.
2930
*/
30-
export default async function render<T>(
31-
component: React.ReactElement<T>,
32-
options: RenderOptions = {},
33-
) {
34-
const { wrapper: Wrapper } = options || {};
31+
export async function render<T>(component: React.ReactElement<T>, options: RenderOptions = {}) {
32+
const { wrapper: Wrapper, createNodeMock } = options || {};
3533

36-
// TODO allow passing some options
37-
const rendererOptions: RootOptions = {};
34+
const rendererOptions: RootOptions = {
35+
textComponents: HOST_TEXT_NAMES,
36+
createNodeMock,
37+
};
3838

3939
const wrap = (element: React.ReactElement) => (Wrapper ? <Wrapper>{element}</Wrapper> : element);
4040
const renderer = await renderWithAsyncAct(wrap(component), rendererOptions);
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import * as React from 'react';
22
import type { HostElement, JsonElement, Root, RootOptions } from 'universal-test-renderer';
33

4-
import act from '../act';
5-
import { addToCleanupQueue } from '../cleanup';
6-
import { getConfig } from '../config';
7-
import type { DebugOptions } from '../helpers/debug';
8-
import { debug } from '../helpers/debug';
9-
import { renderWithAct } from '../render-act';
10-
import { setRenderResult } from '../screen';
11-
import { getQueriesForElement } from '../within';
4+
import act from './act';
5+
import { addToCleanupQueue } from './cleanup';
6+
import { getConfig } from './config';
7+
import type { DebugOptions } from './helpers/debug';
8+
import { debug } from './helpers/debug';
9+
import { HOST_TEXT_NAMES } from './helpers/host-component-names';
10+
import { renderWithAct } from './render-act';
11+
import { setRenderResult } from './screen';
12+
import { getQueriesForElement } from './within';
1213

1314
export interface RenderSyncOptions {
1415
/**
@@ -18,15 +19,15 @@ export interface RenderSyncOptions {
1819
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1920
wrapper?: React.ComponentType<any>;
2021

21-
createNodeMock?: (element: React.ReactElement) => unknown;
22+
createNodeMock?: (element: React.ReactElement) => object;
2223
}
2324

2425
/**
2526
* @deprecated Use `render` (async) instead. This function is provided for migration purposes only.
2627
* Renders test component deeply using React Test Renderer and exposes helpers
2728
* to assert on the output.
2829
*/
29-
export default function unsafe_renderSync<T>(
30+
export function unsafe_renderSync<T>(
3031
component: React.ReactElement<T>,
3132
options: RenderSyncOptions = {},
3233
) {
@@ -36,10 +37,12 @@ export default function unsafe_renderSync<T>(
3637
export type RenderSyncResult = ReturnType<typeof unsafe_renderSync>;
3738

3839
export function renderInternal<T>(component: React.ReactElement<T>, options?: RenderSyncOptions) {
39-
const { wrapper: Wrapper } = options || {};
40+
const { wrapper: Wrapper, createNodeMock } = options || {};
4041

41-
// TODO allow passing some options
42-
const rendererOptions: RootOptions = {};
42+
const rendererOptions: RootOptions = {
43+
textComponents: HOST_TEXT_NAMES,
44+
createNodeMock,
45+
};
4346

4447
const wrap = (element: React.ReactElement) => (Wrapper ? <Wrapper>{element}</Wrapper> : element);
4548
const renderer = renderWithAct(wrap(component), rendererOptions);

0 commit comments

Comments
 (0)